-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Hi,
i got a chart with several series and want to save the visibility state of all series. Is it possible get the state of each series after they are added to the chart?
------ EDIT ------
I tried to use the HIDE/SHOW Event (ChartsEvents.ON_PLOT_HIDE, ChartsEvents.ON_PLOT_SHOW) which are triggered, if a series is hidden or shown.
BUT they don't work, like I would expect them to. If click on the legend and want to hide a series, the "HIDE" Event is triggered, but it still says: "... is visible!", although the opposite is true (it's hidden).
@Override
public void onEvent(ChartsEvent event) {
Series series = (Series) event.getSeries();
if (series.isVisible()) {
System.out.println("[" + series.getName() + "] is visible!");
} else {
System.out.println("[" + series.getName() + "] is NOT visible!");
}
}
Ok, i got it ... it is reeeeeaaaallly ugly, but it works :)
It seems that hide() works correctly, if triggered directly ...
myChart.addEventListener(ChartsEvents.ON_PLOT_HIDE, new EventListener<ChartsEvent>() {
@Override
public void onEvent(ChartsEvent event) {
Series series = (Series) event.getSeries();
//ugly hack ...
if (series.isVisible()) {
series.hide();
}
}
});
Same goes for show() ...
myChart.addEventListener(ChartsEvents.ON_PLOT_SHOW, new EventListener<ChartsEvent>() {
@Override
public void onEvent(ChartsEvent event) {
Series series = (Series) event.getSeries();
//ugly hack ...
if (!series.isVisible()) {
series.show();
}
}
});
With this hack it is possible to sync the visibility from the the client to the server, if you change it from the legend.
I tried to set the missing attr manually, but setAttr is protected :/
Series.class
public void hide() {
setAttr(Attrs.visible, false);
...
}
public void show() {
setAttr(Attrs.visible, true);
...
}
Asked: 2016-04-20 13:45:37 +0800
Seen: 29 times
Last updated: Apr 21 '16