Search code examples
javachartsjasper-reportsjfreechart

Different color for item label in pie chart jasper


i tried to make pie chart with jasper report... I already write the customizer class for the chart...Anyone can give me suggestion about how to make item label color same with series color?

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

I add picture...In picture, "0.07%, 6.18%, 93.74%" have black color...Can we change that color with series color? So "93.74%" have brown color, "6.18%" have magenta color...

Thanks


Solution

  • Finally i found the solution based on @PetterFriberg suggestion...

    in PiePlot method drawLeftLabels and drawRigtLabels change

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

    to

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

    Result

    Result