Greetings,
I've had a lot of fun the last few days, learning the tool and messing around in the code.
I added a bit of code in PiePlot.java to add percentages to the series labels for each wedge.
At line 165 I inserted the following, which builds an array of
percentage values as ints (I wasn't concerned about the loss of precision...):
int[] percentVal = new int[seriesCount];
for ( int seriesIndex = 0; seriesIndex < seriesCount;
seriesIndex++ )
{
Number dataValue = data.getValue(seriesIndex, category);
double value = dataValue.doubleValue();
if (value <= 0)
continue;
// totalValue is established earlier in the code
double x = (value / totalValue) * 100;
int y = (int)x;
percentVal[seriesIndex] = y;
}
And then later on down at (now) line 246, I add the line
which draws the new percentage label:
g2.drawString(percentVal[seriesIndex]+ "%", (float)
labelLocationX , (float)labelLocationY + 10);
The +10 on the labelLocationY offsets the percentage label
from the existing series name label.
Cheers.
Peter
simple Percentage for Pie Charts
RE: simple Percentage for Pie Charts
Peter,
Thanks for posting this - I'll try it out and add it to the next version of JFreeChart.
Regards,
DG.
Thanks for posting this - I'll try it out and add it to the next version of JFreeChart.
Regards,
DG.