画图函数如下:
try {
ArrayList list = volumeValues; //数值LIST,图的纵坐标值
// Throw a custom NoDataException if there is no data
if (list.size() == 0) {
System.out.println("No data has been found");
throw new NoDataException();
}
// Create and populate a CategoryDataset
Iterator iter = list.listIterator();
DefaultCategoryDataset dataset = new DefaultCategoryDataset();
int i = 0;
while (iter.hasNext()){ //datas为周一到周日的LIST,为 横坐标
Integer volume = (Integer)iter.next();
dataset.addValue(new Integer((volume != null) ? volume.toString() : "0"),
(String)dates.get(i), (String)dates.get(i));
i ++;
}
// Create the chart object
CategoryAxis categoryAxis = new CategoryAxis("");
ValueAxis valueAxis = new NumberAxis("");
BarRenderer renderer = new BarRenderer();
Plot plot = new CategoryPlot(dataset, categoryAxis, valueAxis, renderer);
Font chineseFont = new Font("SimSung", Font.BOLD, 18);
JFreeChart chart = new JFreeChart("", chineseFont, plot, false);
chart.setBackgroundPaint(java.awt.Color.white);
// Write the chart image to the temporary directory
ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());
filename = ServletUtilities.saveChartAsPNG(chart, 500, 250, info, session);
// Write the image map to the PrintWriter
ChartUtilities.writeImageMap(pw, filename, info);
pw.flush();