sorting does not work properly
sorting does not work properly
If I try to sort my DefaultPieDataset, the colours in the legend do not match to the colours in the chart. Anybody expierienced the same problem? Unsorted, the colours in legend and chart match.
-
- JFreeChart Project Leader
- Posts: 11734
- Joined: Fri Mar 14, 2003 10:29 am
- antibot: No, of course not.
- Contact:
Can you post your JFreeChart version number and, if possible, a small demo app that illustrates the problem. I've fixed something like this before, but you may have uncovered another variation of it...
David Gilbert
JFreeChart Project Leader
Read my blog
Support JFree via the Github sponsorship program
JFreeChart Project Leader


Code: Select all
DefaultPieDataset pieDataset = new DefaultPieDataset();
ClientFonddepot fonddepot;
for(int i = 0; i < fonds.length; i++){
fonddepot = (ClientFonddepot) fonds[i];
pieDataset.setValue(fonddepot.getFonds(), fonddepot.getWert().getAmount());
}
[...]
JFreeChart chart = ChartFactory.createPieChart("", pieDataset, true, false, false);
final PiePlot piePlot1 = (PiePlot) chart.getPlot();
piePlot1.setForegroundAlpha(0.5f);
piePlot1.setLabelGenerator(new CustomLabelGenerator());
LegendTitle legend1 = new LegendTitle(piePlot1);
Code: Select all
JFreeChart chart2 = ChartFactory.createPieChart("", pieDataset2, true, false, false);
final PiePlot piePlot2 = (PiePlot) chart2.getPlot();
LegendTitle legend2 = new LegendTitle(piePlot2);
chart.setSubtitles(new ArrayList());
chart.addLegend(legend2);
chart.addLegend(legend1);
Without
Code: Select all
pieDataset.sortByValues(SortOrder.DESCENDING);