How to stroke a PieChart's legend items (not slices)

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
NickDecker
Posts: 3
Joined: Wed Sep 10, 2014 10:12 pm
antibot: No, of course not.

How to stroke a PieChart's legend items (not slices)

Post by NickDecker » Fri Sep 12, 2014 1:29 am

Hi,

Is there any way to control the stroke on a PieChart's legend items independent of the sectionOutlineStroke? Right now I can modify the stroke for both the legend shapes and the pie slices with:

Code: Select all

plot.setBaseSectionOutlinePaint()
plot.setBaseSectionOutlineStroke()
But I want to stroke the legend shapes with a different color than the pie slices.

Originally I thought I could get the legend item collection from the plot, iterate through it and change the outlineStroke and outlinePaint for each legend item. The problem is that there's no way to set the legend item collection back on the plot. I can easily do this with bar/line charts via their renderer, but the PiePlot doesn't have a renderer. Is there any way to do this so that I can get my PieChart legend items to match my BarChart legend items?

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Re: How to stroke a PieChart's legend items (not slices)

Post by david.gilbert » Wed Sep 17, 2014 8:55 pm

The easiest way would be to directly modify the PiePlot source (or override the getLegendItems() method). Change this object creation:

Code: Select all

LegendItem item = new LegendItem(label, description,
                            toolTipText, urlText, true, shape, true, paint,
                            true, outlinePaint, outlineStroke,
                            false,          // line not visible
                            new Line2D.Float(), new BasicStroke(), Color.black);
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

Locked