Posted on 2009-12-28 14:31
landor 阅读(1369)
评论(0) 编辑 收藏 所属分类:
导出与图表
//访问量统计时间线
TimeSeries timeSeries = new TimeSeries("数字统计1", Month.class);
//时间数据集合
TimeSeriesCollection lineDataset = new TimeSeriesCollection();
//构造数据
timeSeries.add(new Month(1, 2009), 100);
timeSeries.add(new Month(2, 2009), 200);
timeSeries.add(new Month(3, 2009), 100);
timeSeries.add(new Month(4, 2009), 200);
timeSeries.add(new Month(5, 2009), 100);
timeSeries.add(new Month(6, 2009), 200);
timeSeries.add(new Month(7, 2009), 100);
timeSeries.add(new Month(8, 2009), 200);
timeSeries.add(new Month(9, 2009), 100);
timeSeries.add(new Month(10, 2009), 200);
timeSeries.add(new Month(11, 2009), 100);
timeSeries.add(new Month(12, 2009), 200);
lineDataset.addSeries(timeSeries);//填入集合
JFreeChart chart = ChartFactory.createTimeSeriesChart("数字统计图", "月份", "数字", lineDataset, true, true, true);
//设置标题字体
chart.getTitle().setFont(new Font("黑体", 12, 12));
chart.getLegend().setItemFont(new Font("宋体",Font.PLAIN,12));
XYPlot plot = (XYPlot) chart.getPlot();
NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
ValueAxis domainAxis = plot.getDomainAxis();
//当timeSeries为null时,显示
plot.setNoDataMessage("没有数据显示");
//设置X轴坐标上的字体
domainAxis.setTickLabelFont(new Font("sans-serif",Font.PLAIN,11));
//设置X轴的标题字体
domainAxis.setLabelFont(new Font("宋体",Font.PLAIN,12));
//设置Y轴坐标上的字体
rangeAxis.setTickLabelFont(new Font("sans-serif",Font.PLAIN,12));
//设置Y轴的标题字体
rangeAxis.setLabelFont(new Font("黑体",Font.PLAIN,12));
ChartUtilities.writeChartAsJPEG(response.getOutputStream(),chart,500,300);
out.clear();
pageContext.pushBody();