Question

I have a JSP that is rendering a fusion chart. The chart uses Spring to fetch the data it renders using MyBatis as the ORM. When I hit the hyperlink that render's the chart, the page takes forever to load because the data fetched is large. I want the chart to show the "loading data" bar in the chart when the query is running. The other parts of JSP should be visible and the chart should show "loading" when it's fetching the data. Using flash version of FUSION with XML configuration. Thanks in advance.

Was it helpful?

Solution

It seems that your page is taking lots of time to display because there is lots of data to be got from ORM. The "Loading Chart" message gets displayed when the JSP page is displayed and when FusionCharts is in its process of rendering the chart. But in your case, the JSP page is not rendered at all.

As a solution to this problem, try separating both the processes, such that there are two server-side pages

  1. To whom control goes to when you click on hyperlink and displays the JSP page
  2. On load of JSP page, call AJAX function and send request to another server-side page which retrieves the data required for FusionCharts to load. On receiving the data, the chart can plot the data. The "Loading chart" message gets shown when the chart is plotting the data. And, till you receive the data, you can show a custom message inside the div.

Since AJAX notifies you when it has come back, you can achieve what you want by doing this.

OTHER TIPS

Refer the code below and make sure you use "PrintWriter" object in the data provider page (Servlet) to output XML/JSON data to the caller (loadFusionCharts() function) of the page

<script language='JavaScript'> //in the head section
/* create AJAX object */
function getXMLObject()
    {
        var xmlHttp = false;
        try {
            xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try {
                xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e2) {
                xmlHttp = false;
            }
        }
        if (!xmlHttp && typeof XMLHttpRequest != 'undefined') {
            xmlHttp = new XMLHttpRequest();
        }
        return xmlHttp;
    }

var xmlhttp = new getXMLObject();

/*function to be called "onload" of body */
function loadFusionCharts()

{
  if (xmlhttp.readyState == 4 || xmlhttp.readyState == 0)
    {
    var url="someURL";  //URL of data provider page that gets data from database
    xmlhttp.open("POST", url, true);
    xmlhttp.onreadystatechange = handleServerResponse;
    xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
    xmlhttp.send(null);
    }
}
/* gets called when AJAX response comes back after executing the data provider page*/
function handleServerResponse()
    { 
        if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
        {
            var chartData = xmlhttp.responseText;
            if (chartData!="") 
            {
          var myChart = new FusionCharts( "./FusionCharts/ScrollCombi2D.swf","ChartId", "1040", "320", "0", "0");
          myChart.setXMLData(chartData);
          myChart.render("fcDiv");  
            }else{
                document.getElementById('fcDiv').innerHTML="Could not get data to render the chart";
            }
         }
    }

</script>
</head>
<body onload='loadFusionCharts()'>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top