Click on Legend To Hide Series

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
jesse
Posts: 8
Joined: Fri Nov 17, 2006 7:16 pm

Click on Legend To Hide Series

Post by jesse » Thu Dec 14, 2006 11:49 pm

Has anyone tried to hide a series by clicking on its legend entry?

I could only think of adding hide JCheckboxes on the chart's right click menu that toggled the visibility.

Is there a better way to do this?

gmerte
Posts: 7
Joined: Wed Jan 24, 2007 4:13 pm

Post by gmerte » Wed Jan 24, 2007 4:14 pm

I'm also looking for that functionality. Did you manage to do it?

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 Jan 24, 2007 4:18 pm

You can add a ChartMouseListener to the ChartPanel and look out for LegendItemEntities. If you have the JFreeChart Developer Guide (and thus the demo source code), check out MouseListenerDemo3.java.

From there, you can hide a series either by physically removing it from the dataset, or setting the visibility flag in the renderer (not all renderers support this yet).
David Gilbert
JFreeChart Project Leader

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

jesse
Posts: 8
Joined: Fri Nov 17, 2006 7:16 pm

Post by jesse » Fri Jan 26, 2007 6:18 pm

The problem with that is when you toggle a series' visibility, the legend's entry gets hidden too. How can you click on the entry to show the series again? I can only guess there is a setting to allow a series to be hidden without hiding the legend entries.

Locked