Why does chart.removeLegend(); change the colors of a chart?

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
Arkkimaagi
Posts: 25
Joined: Wed Jun 09, 2004 6:15 am
Location: Helsinki, Finland
Contact:

Why does chart.removeLegend(); change the colors of a chart?

Post by Arkkimaagi » Wed Jun 29, 2005 1:48 pm

When I use XYPlot and XYLineAndShapeRenderer with the latest JFreeChart, removing legend reverses the order of the automatically colored lines.

Why? Can this be fixed somehow?
~ Arkkimaagi ~
Experto Credite

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 » Wed Jun 29, 2005 1:55 pm

This is a recently reported bug - no fix is available yet.
David Gilbert
JFreeChart Project Leader

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

KevinWorkman
Posts: 2
Joined: Wed Feb 20, 2013 7:32 pm
antibot: No, of course not.

Re: Why does chart.removeLegend(); change the colors of a ch

Post by KevinWorkman » Wed Feb 20, 2013 7:37 pm

Sorry to be a necromancer here, but I'm still seeing this in version 1.0.14 of JFreeChart. Is there a way around this?

My use case is I have one big chart that has the legend, and then a bunch of little charts that show the same series, but from different perspectives. So I'd like the series in the little charts to have the same colors as in the big chart, but not show the legend on every smaller chart. Keeping the legend on the little charts works fine, but is really ugly. Removing the legends causes the colors to be wrong (apparently reversed).

kkonkler
Posts: 3
Joined: Wed Mar 13, 2013 7:23 pm
antibot: No, of course not.

Re: Why does chart.removeLegend(); change the colors of a ch

Post by kkonkler » Wed Mar 13, 2013 7:28 pm

I too am seeing this exact same issue in version 1.0.14. Instead of running chart.removeLegend(), I am using chart.getLegend().setVisible(false);

I have seen in in two scenarios:

1. Just like KevinWorkman, I have one main XYPlot with several other plots showing the same data with different perspectives. The main plot has a certain order and the other plots have the order reversed.

2. I have a scatter plot that you can choose which set of data to view. When switching, the XYDataset gets all of it's XYSeries cleared and new data is added. When switching through the data, the colors chosen are random when the legend is hidden. When the legend is in view, the colors are the same every time.

AdamST
Posts: 1
Joined: Wed Feb 26, 2014 12:01 am
antibot: No, of course not.

Re: Why does chart.removeLegend(); change the colors of a ch

Post by AdamST » Wed Feb 26, 2014 12:09 am

Hi, I happened to accidentally find out a counter measure that works fine.
Try this line after "removeLegend();" or "chart.getLegend().setVisible(false);"; it will get your colours back to the previous order palette.

JFreeChart chart;
[code here...]
chart.getXYPlot().setSeriesRenderingOrder(SeriesRenderingOrder.FORWARD);

Regards,
Adam

Locked