饼图碧玉中项目标签的不同颜色

时间:2016-01-13 03:59:08

标签: java charts jasper-reports jfreechart

我试图用jasper报告制作饼图...我已经为图表编写了自定义程序类......任何人都可以给我一些关于如何使项目标签颜色与系列颜色相同的建议?

PiePlot piePlot = (PiePlot)chart.getPlot();
PieDataset pieDataset = piePlot.getDataset();
piePlot.setOutlineVisible(false);
chart.setBackgroundPaint(Color.white);              
piePlot.setLabelFont(new Font("Arial", Font.CENTER_BASELINE, 7));                              piePlot.setShadowPaint(null);        
piePlot.setLabelOutlinePaint(null);
piePlot.setLabelShadowPaint(null);
piePlot.setLabelBackgroundPaint(null);      
piePlot.setSectionOutlinesVisible(false);

enter image description here

我添加图片...在图片中," 0.07%,6.18%,93.74%"有黑色......我们可以用系列颜色改变颜色吗?所以" 93.74%"有棕色," 6.18%"有洋红色...

由于

1 个答案:

答案 0 :(得分:1)

最后我找到了基于@PetterFriberg建议的解决方案......

PiePlot方法drawLeftLabelsdrawRigtLabels更改

TextBlock block = TextUtilities.createTextBlock(label,
                        this.labelFont, this.labelPaint, maxLabelWidth,
                        new G2TextMeasurer(g2));

TextBlock block = TextUtilities.createTextBlock(label,
                        this.labelFont, lookupSectionPaint(leftKeys.getKey(i)), maxLabelWidth,
                        new G2TextMeasurer(g2));

<强>结果

Result