0

does not execute event onPlotShow and onPlotHide in charts type pie

asked 2019-05-30 23:49:09 +0800

rijhar7 gravatar image rijhar7
12

updated 2019-06-03 10:18:12 +0800

cor3000 gravatar image cor3000
4671 2 7
ZK Team

Help! I am trying to implement the events that show and hide series in pie chart but do not recognize or execute those events.

This is my implementation:

chart.addEventListener (ChartsEvents.ON_PLOT_HIDE, new EventListener <Event> () {
    public void onEvent (Event event) throws Exception {
    // ...
    }
});

Please someone who can guide me ?. The version of zk I use is ZK 8.5.1.2 EE

delete flag offensive retag edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2019-06-19 17:45:50 +0800

cor3000 gravatar image cor3000
4671 2 7
ZK Team

Here an example showing the events working:

zul:

<zk xmlns:w="client">
    <charts id="pieChart" apply="PieChartComposer_111246" />
    <button label="toggle 'Past' series" 
            w:onClick="var ser = zk.$('$pieChart').engine.series[0];
                       ser.setVisible(!ser.visible)"/>
    <button label="toggle 'Future' series" 
            w:onClick="var ser = zk.$('$pieChart').engine.series[1];
                       ser.setVisible(!ser.visible)"/>
</zk>

java:

import org.zkoss.chart.Charts;
import org.zkoss.chart.Series;
import org.zkoss.chart.plotOptions.PiePlotOptions;
import org.zkoss.zk.ui.util.Clients;
import org.zkoss.zk.ui.util.Composer;

import static org.zkoss.chart.ChartsEvents.ON_PLOT_HIDE;
import static org.zkoss.chart.ChartsEvents.ON_PLOT_SHOW;

public class PieChartComposer_111246 implements Composer<Charts> {
    @Override
    public void doAfterCompose(Charts chart) throws Exception {
        chart.setType(Charts.PIE);

        Series past = chart.getSeries(0);
        Series future = chart.getSeries(1);
        past.setName("Past");
        future.setName("Future");

        future.addPoint("Linux", 60);
        future.addPoint("Windows", 20);
        future.addPoint("MacOS", 20);
        past.addPoint("Linux", 33.333);
        past.addPoint("Windows", 33.333);
        past.addPoint("MacOS", 33.333);

        chart.getPlotOptions().getPie().setShowInLegend(true);

        PiePlotOptions pastPlotOptions = new PiePlotOptions();
        past.setPlotOptions(pastPlotOptions);
        pastPlotOptions.setSize("40%");

        PiePlotOptions futurePlotOptions = new PiePlotOptions();
        future.setPlotOptions(futurePlotOptions);
        futurePlotOptions.setInnerSize("60%");
        futurePlotOptions.setSize("80%");

        chart.addEventListener(ON_PLOT_HIDE, event -> Clients.log(event.toString()));
        chart.addEventListener(ON_PLOT_SHOW, event -> Clients.log(event.toString()));
    }
}

The event work as expected, however highcharts is rendering Pie charts differently, so that legend items correspond to dataPoints instead of Series.

When hiding/showing a complete series (via javascript) the events fire as expected and the listeners at server side execute accordingly.

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

RSS

Stats

Asked: 2019-05-30 23:49:09 +0800

Seen: 5 times

Last updated: Jun 19

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