我是Bean的方式显示饼图的,但是显示结果中图例中的文字没有显示出来,是几个小方框。设置数据集的代码很简单:
/**
 * 查询结果数据整理,生成饼图数据集
 */
public static DefaultPieDataset createDataset(){
 DefaultPieDataset dataset = new DefaultPieDataset();
 ExcelService service = new ExcelService();
 
 try {
 // 数据库关联数据查询
List<List> proList = service.productDataGet();
if (proList.size() > 0 ) {
for (int i = 0; i < proList.size(); i++) {

// 取得产品类型及销售额
List<Object> tmpList = proList.get(i);
dataset.setValue(tmpList.get(0).toString(), (Integer)tmpList.get(1));
}
}

} catch (Exception e) {
e.printStackTrace();
}
return dataset;
}请指点迷津,谢谢!!生成饼图的语句:JFreeChart chart = ChartFactory.createPieChart3D(title,data,true,true,false);

解决方案 »

  1.   


     JFreeChart chart = ChartFactory.createPieChart3D(chartTitle, // chart
                    // title
                    dataset,// data
                    true,// include legend
                    true, false);        // 使下说明标签字体清晰,去锯齿类似于
            // chart.getRenderingHints().put(RenderingHints.KEY_TEXT_ANTIALIASING,RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);的效果
            chart.setTextAntiAlias(false);
            // 图片背景色
            chart.setBackgroundPaint(Color.white);
            // 设置图标题的字体重新设置title
            Font font = new Font("隶书", Font.BOLD, 25);
            TextTitle title = new TextTitle(chartTitle);
            title.setFont(font);
            chart.setTitle(title);        PiePlot3D plot = (PiePlot3D) chart.getPlot();
            // 图片中显示百分比:默认方式        // 指定饼图轮廓线的颜色
            // plot.setBaseSectionOutlinePaint(Color.BLACK);
            // plot.setBaseSectionPaint(Color.BLACK);        // 设置无数据时的信息
            plot.setNoDataMessage("无对应的数据,请重新查询。");        // 设置无数据时的信息显示颜色
            plot.setNoDataMessagePaint(Color.red);        // 图片中显示百分比:自定义方式,{0} 表示选项, {1} 表示数值, {2} 表示所占比例 ,小数点后两位
            plot.setLabelGenerator(new StandardPieSectionLabelGenerator(
                    "{0}={1}({2})", NumberFormat.getNumberInstance(),
                    new DecimalFormat("0.00%")));
            // 图例显示百分比:自定义方式, {0} 表示选项, {1} 表示数值, {2} 表示所占比例
            plot.setLegendLabelGenerator(new StandardPieSectionLabelGenerator(
                    "{0}={1}({2})"));        plot.setLabelFont(new Font("SansSerif", Font.TRUETYPE_FONT, 12));        // 指定图片的透明度(0.0-1.0)
            plot.setForegroundAlpha(0.65f);
            // 指定显示的饼图上圆形(false)还椭圆形(true)
            plot.setCircular(false, true);        // 设置第一个 饼块section 的开始位置,默认是12点钟方向
            plot.setStartAngle(90);        // // 设置分饼颜色
            plot.setSectionPaint(pieKeys[0], new Color(244, 194, 144));
            plot.setSectionPaint(pieKeys[1], new Color(144, 233, 144));
      

  2.   


    传图片需要先把图片上传到服务器,得到一个可以访问的URL地地址,上传到CSDN就可以了。