I have created line chart using jfreeChart API inside jsp and servlet.
Following is the code in servlet
// Get the output stream from the response object:
OutputStream out = response.getOutputStream();
// Set the HTTP Response Type:
response.setContentType("image/png");
XYSeries series = new XYSeries("Average Weight1233");
series.add(1.48, 20.0);
series.add(1.52, 25.0);
series.add(2.02, 50.0);
series.add(2.05, 65.0);
series.add(3.30, 2);
series.add(3.52, 50);
XYDataset xyDataset = new XYSeriesCollection(series);
// Create chart:
JFreeChart chart
= ChartFactory.createXYLineChart("XYLine Chart using JFreeChart",
"Age", "Weight",xyDataset,
PlotOrientation.VERTICAL,
true, true, false);
// Write the data to the output stream:
ChartUtilities.writeChartAsPNG(out, chart, 400, 300);
It creates horizontal number automatically from values that I have added on XYSeries
But I want to set that value manually.
Is it possible? How?
No comments:
Post a Comment