sorting does not work properly

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
schlikkes
Posts: 4
Joined: Mon Sep 17, 2007 3:22 pm
Contact:

sorting does not work properly

Post by schlikkes » Mon Sep 24, 2007 10:06 am

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.

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

Post by david.gilbert » Mon Sep 24, 2007 3:22 pm

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

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

schlikkes
Posts: 4
Joined: Mon Sep 17, 2007 3:22 pm
Contact:

Post by schlikkes » Tue Sep 25, 2007 10:08 am

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);
As I need two different legends for this chart, I am building two charts and two legends but adding the legend of the second chart to the first chart.

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);
Could this be the problem?

Without

Code: Select all

pieDataset.sortByValues(SortOrder.DESCENDING);
the legend items and the parts of the chart match. With sorting the colors do not match.

Locked