问题
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?
回答1:
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.
回答2:
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.
来源:https://stackoverflow.com/questions/11904583/jfreechart-combineddomainxyplot-maintaining-order-of-plots