JFreeChart combinedDomainXYPlot - maintaining order of plots

谁说我不能喝 提交于 2020-01-06 15:40:54

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!