charts icon indicating copy to clipboard operation
charts copied to clipboard

Legend item click does not update series visibility property

Open AndrasJanurik opened this issue 6 years ago • 1 comments

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()));

AndrasJanurik avatar Mar 30 '18 10:03 AndrasJanurik

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...

echarlus avatar Jun 03 '19 20:06 echarlus