DefaultCategoryDataset dataset = new DefaultCategoryDataset();
dataset.addValue(520,"深圳","香蕉");
dataset.addValue(380,"深圳","橘子");
dataset.addValue(420,"深圳","橙子");
dataset.addValue(250,"深圳","桃子");
JFreeChart jfreechart = ChartFactory.createBarChart3D("水果销量统计图",//图表标题
"水果", //x轴标题
"销量", //y轴标题
dataset, //绘制图数据集
PlotOrientation.VERTICAL,//控制柱状图的绘制方向
false, //用于设定是否显示图例
false, //用于设定是否采用标准生成器器
false //用于设定是否包生成链接
);
//解决乱码问题
jfreechart.getTitle().setFont(new Font("宋体",Font.BOLD,16));
CategoryPlot plot =jfreechart.getCategoryPlot();//图形的绘制结构对象
//x轴
CategoryAxis domainAxis= plot.getDomainAxis();
domainAxis.setLabelFont(new Font("宋体",Font.PLAIN,12));//轴标题
domainAxis.setTickLabelFont(new Font("宋体",Font.PLAIN,12));//轴数值
domainAxis.setTickLabelPaint(Color.BLUE);//字体颜色
domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90);//横轴上的字体斜显示
//y轴
ValueAxis rangeAxis= plot.getRangeAxis();
rangeAxis.setLabelFont(new Font("宋体",Font.PLAIN,12));
rangeAxis.setTickLabelFont(new Font("宋体",Font.PLAIN,12));
rangeAxis.setTickLabelPaint(Color.BLUE);
//尝试解决柱状图上数据的显示
BarRenderer renderer =(BarRenderer)plot.getRenderer();
renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
renderer.setSeriesOutlinePaint(0, Color.BLACK);//边框为黑色
renderer.setSeriesPaint(0,new Color(0,255,0));//实报柱子的颜色为绿色
renderer.setSeriesOutlinePaint(0,Color.red);//实际柱子颜色为红色
renderer.setBaseItemLabelsVisible(true);
NumberFormat nf= NumberFormat.getNumberInstance();
//这里本该是热点显示设置的,为什么什么都不显示了,以窗体形式可以显示热区,以jsp时,就不显示了,为什么?
renderer.setToolTipGenerator(generator);
PrintWriter pw = new PrintWriter(out);
StandardEntityCollection sec = new StandardEntityCollection();
//生成RenderingInfo实例,info参数就是图片的热点信息
ChartRenderingInfo info = new ChartRenderingInfo(sec);
String filename = ServletUtilities.saveChartAsPNG(jfreechart, 800, 500, info, session);
ChartUtilities.writeImageMap(pw, filename, info, false);
String graphURL =request.getContextPath() + "/abc/DisplayChart?filename=" +filename;
%>
<html>
<body>
<img src="<%=graphURL %>" width=800 height=500 border=0 usemap="<%=filename %>"/>
</body>
</html>
517




被折叠的 条评论
为什么被折叠?



