charts
charts copied to clipboard
Legend item click does not update series visibility property
Clicking a legend item it will toggle the series visibility on the screen, which is the proper operation. But it does not actually update the visible property of the series, so calling isVisible() will still return true after hiding a series.
Simple workaround Just adding the following legend item click listener will work around the problem:
chart.addLegendItemClickListener(event -> ((AbstractSeries) event.getSeries()).setVisible(!((AbstractSeries) event.getSeries()).isVisible()));
Just stumbled across the same issue with charts 4.1.0. I was wondering if it was on purpose ... I solved the issue using a trick similar to yours ... Fixing it in the code seems pretty easy (Chart.java in onSeriesHide & onSeriesShow). One needs to ensure that resolved Series is an instance of AbstractSeries and then call setVisible accordingly ... I'll submit a pull request for this...