1

ZK Charts: Hide Series

asked 2016-04-20 13:45:37 +0800

IngoB gravatar image IngoB flag of Germany
256 6

updated 2016-04-21 10:00:14 +0800

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!");
        }
    }
delete flag offensive retag edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2016-04-21 12:29:49 +0800

IngoB gravatar image IngoB flag of Germany
256 6

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);
    ...
}
link publish delete flag offensive edit
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow
1 follower

RSS

Stats

Asked: 2016-04-20 13:45:37 +0800

Seen: 24 times

Last updated: Apr 21 '16

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More