Search code examples
javapie-chartjfreechart

Is there a way to set individual label link colors in JFreeChart's PiePlot?


I see that I can use setLabelLinkPaint() to universally apply a color to all label links, but I'm looking to set each individual label link to a different color. Is there a way to do this?


Solution

  • It looks like for now the most straightforward way to approach this problem is to subclass the PiePlot class and override the drawRightLabel and drawLeftLabel methods. In my case, I needed to have the label link color match the corresponding pie chart section, so in my overridden methods I set g2.setPaint(getSectionPaint(record.getKey())).

    My advice to anyone trying to do something similar is to watch out for casting errors if casting from a JFreeChart chart object. You will likely have to additionally subclass ChartFactory and modify it so that it uses your subclassed PiePlot and not the original one.