日期:2014-05-18  浏览次数:20665 次

如何在jfreechart柱状图中的每个柱子上显示数值的问题
小弟刚接触jfreechart,在网上找了个柱状图的列子,我用的是jfreechart1.05的。网上的列子太旧,小弟做了点修改,图出来了,就是每跟柱子上无法显示数值,不知道何缘故。代码如下:

<%@   page   contentType= "text/html;charset=GBK "%>
<%@   page   import= "java.awt.Color "%>
<%@   page   import= "org.jfree.chart.ChartFactory "%>
<%@   page   import= "org.jfree.chart.JFreeChart "%>
<%@   page   import= "org.jfree.chart.plot.PlotOrientation "%>
<%@   page   import= "org.jfree.chart.servlet.ServletUtilities "%>
<%@   page   import= "org.jfree.data.category.CategoryDataset "%>
<%@   page   import= "org.jfree.data.general.DatasetUtilities "%>
<%@   page   import= "org.jfree.chart.plot.CategoryPlot "%>
<%@   page   import= "org.jfree.chart.axis.CategoryAxis "%>
<%@   page   import= "org.jfree.chart.axis.ValueAxis "%>
<%@   page   import= "org.jfree.chart.renderer.category.BarRenderer3D "%>
<%@   page   import= "org.jfree.chart.axis.AxisLocation "%>

<%
double[][]   data   =   new   double[][]   {{672,   766,   223,   540,   126},{325,   521,   210,   340,   106},{332,   256,   523,   240,   526}};
String[]   rowKeys   =   { "苹果 ", "梨子 ", "葡萄 "};
String[]   columnKeys   =   { "北京 ", "上海 ", "广州 ", "成都 ", "深圳 "};
CategoryDataset   dataset   =   DatasetUtilities.createCategoryDataset(rowKeys,   columnKeys,   data);

JFreeChart   chart   =   ChartFactory.createBarChart3D( "水果销量图统计 ",
                                      null,
                                      null,
                                      dataset,
                                      PlotOrientation.VERTICAL,
                                      true,false,false);
chart.setBackgroundPaint(Color.WHITE);
CategoryPlot   plot   =   chart.getCategoryPlot();

CategoryAxis   domainAxis   =   plot.getDomainAxis();
//domainAxis.setVerticalCategoryLabels(false);

plot.setDomainAxis(domainAxis);

ValueAxis   rangeAxis   =   plot.getRangeAxis();
//设置最高的一个   Item   与图片顶端的距离
rangeAxis.setUpperMargin(0.15);
//设置最低的一个   Item   与图片底端的距离
rangeAxis.setLowerMargin(0.15);
plot.setRangeAxis(rangeAxis);

BarRenderer3D   renderer   =   new   BarRenderer3D();
renderer.setBaseOutlinePaint(Color.BLACK);
renderer.setWallPaint(Color.gray);//设置   Wall   的颜色
//设置每种水果代表的柱的颜色
renderer.setSeriesPaint(0,   new   Color(0,   0,   255));
renderer.setSeriesPaint(1,   new   Color(0,   100,   255));
renderer.setSeriesPaint(2,