|
Usually your charts will be loaded with the page using indirect chart request method. In some cases however you might need to update the chart
without refreshing the entire page. This can happen when you want to show the results of a drill-down by presenting another chart, or want to
periodically update the chart, but not the entire page.
Depending upon the chart's format and the plugin for this format you will need to perform different actions. This example demonstrates
updating the standard image chart without refreshing the page. Note that such chart cannot be made interactive unless alternative formats
(Flash, SVG) are used or Ajax objects are employed to replace html.
To refresh a chart you need to create a page that will provide to the browser a new chart as a binary stream in the appropriate format. In this
example the chart's model is initially populated and stored in the session object and when a new request is processed the first column is deleted
and a new column with random values is inserted:
MxStandardChartModel model = (MxStandardChartModel)
request.getSession().getAttribute("modelXML");
if(model == null) {
model = new MxStandardChartModel();
for(int i=0;i<4;i++)
model.insertCol(""+(i-4),null,-1);
model.insertRow("",new double[] {10,70,40,20} ,-1);
request.getSession().setAttribute("modelXML", model);
}
model.deleteCol(0);
double column [] = new double[] {Math.round(Math.random()*99)};
model.insertCol(request.getParameter("count"), column, -1 );
Once the model is refreshed and a new chart description is produced, you need to write the chart's bits into the server's response object.
The easiest way to do so is to use WebCharts3D's standard function writeBytesTo. This function will automatically set both content-type and content-length
headers of the response to correct values, write bytes and close the stream:
svr.writeBytesTo(myChart,response);
Note that the page that returns byte stream should not have any characters (including '\n' and '\r') between JSP tags and should not use out.write().
|