0

I would like to hide/show plots in combinedDomainXYPlot but the class only allows to add/remove plots. For instance, if I have 3 plots, I remove the second, and then add it, visually it is going to add it as the third chart at the bottom. Is there any way to maintain the charts order visually?

Bober02
  • 15,034
  • 31
  • 92
  • 178
  • What happens when you remove them all and add the desired ones back in order? – trashgod Aug 10 '12 at 19:42
  • That is what I was thinking about but I need to make sure the ordering is right using a separate collection... – Bober02 Aug 11 '12 at 07:45
  • I'd build the display list while looping through the selection model; I was curious if the display effect was acceptable. – trashgod Aug 11 '12 at 11:45
  • I dont quite get that trashgod. Could you elaborate? You want to iterate through the selection mofel i.e. my own construct, and tthen based onn the selectiion add and remove to the plot? – Bober02 Aug 12 '12 at 08:21

2 Answers2

2

I'd use a ListSelectionModel, which is available to both JList, shown here, and JTable, shown here. The former has a flexible layout, while the latter has a convenient JCheckbox renderer/editor.

Lets assume your model ultimately produces a List<Plot> named selected. You can loop though the getSubplots() list to remove() all current plots, then loop through your List<Plot> to add() each selected plot back.

Addendum: If the subplots are otherwise identical, you may be able to to add() or remove() a minimum number of subplots and replace the models of those that remain using setDataset(), shown here. It's slightly more complicated but perhaps less visually disruptive.

Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045
0

You could possibly use AbstractRenderer.setSeriesVisible depending on the Renderer you are using.

This hides rather than removes the series so order is unaffected. If you have access to the JFreeChart demo check out HideSeriesDemo1 for an example.

GrahamA
  • 5,875
  • 29
  • 39