None of the ChartsEvent seemed to work on combination charts although they work on basic charts.
test.zul
<window apply="test.TestComposer"> <charts id="chart" title="Combination chart"/> <label id="infoChartsEvent" /> </window>
TestComposer.java
package test; import java.util.Arrays; import java.util.List; import java.util.Map.Entry; import org.zkoss.chart.Charts; import org.zkoss.chart.ChartsEvent; import org.zkoss.chart.Color; import org.zkoss.chart.LabelsItem; import org.zkoss.chart.Marker; import org.zkoss.chart.Point; import org.zkoss.chart.Series; import org.zkoss.chart.plotOptions.PiePlotOptions; import org.zkoss.zk.ui.select.SelectorComposer; import org.zkoss.zk.ui.select.annotation.Listen; import org.zkoss.zk.ui.select.annotation.Wire; import org.zkoss.zul.Label; import org.zkoss.zul.Window; @SuppressWarnings("serial") public class TestComposer extends SelectorComposer<Window> { @Wire Charts chart; @Wire Label infoChartsEvent; public void doAfterCompose(Window comp) throws Exception { super.doAfterCompose(comp); List<Color> colors = chart.getColors(); chart.getXAxis().setCategories(`Data.getCategories()); chart.getTooltip().setHeaderFormat("{point.key}: "); chart.getTooltip().setPointFormat("{point.y}"); LabelsItem item = new LabelsItem("Total fruit consumption"); item.setStyle("left: '40px'; top: '8px'; color: 'black'"); chart.getLabels().setItems(Arrays.asList(item)); for (Entry<String, Integer[]> entry : ComboData.getConsumption() .entrySet()) { Series series = new Series(entry.getKey()); series.setType("column"); series.setData(entry.getValue()); chart.addSeries(series); } Series average = new Series("Average"); average.setType("spline"); average.setData(ComboData.getAverage()); Marker marker = average.getMarker(); marker.setLineWidth(2); marker.setLineColor(chart.getColors().get(3)); marker.setFillColor("white"); chart.addSeries(average); Series total = new Series("Total consumption"); total.setType("pie"); int i = 0; for (String person : ComboData.getConsumption().keySet()) { Point point = new Point(person, ComboData.getSum(person)); point.setColor(colors.get(i++)); total.addPoint(point); } PiePlotOptions plotOptions = new PiePlotOptions(); plotOptions.setCenter(100, 80); plotOptions.setSize(100); plotOptions.setShowInLegend(false); plotOptions.getDataLabels().setEnabled(false); plotOptions.getTooltip().setPointFormat("{point.y} fruits"); total.setPlotOptions(plotOptions); chart.addSeries(total); } private static final String EVENTS_TO_LISTEN = "onPlotClick = #chart; " + "onPlotCheckboxClick = #chart; " + "onPlotLegendItemClick = #chart; " + "onPlotShow = #chart; " + "onPlotHide = #chart; " + "onPlotMouseOver = #chart; " + "onPlotMouseOut = #chart; " + "onPlotSelect = #chart; " + "onPlotUnSelect = #chart; " + "onPlotDrillUp = #chart; " + "onPlotDrillDown = #chart"; @Listen(EVENTS_TO_LISTEN) public void onChartsEvent(ChartsEvent event) { infoChartsEvent.setValue("Event: " + event.getName()); } }
ComboData.java
package test; import java.util.LinkedHashMap; import java.util.Map; public class ComboData { private static String[] categories; private static Map<String, Integer[]> consumption; private static final int unitSize = 5; static { categories = new String[] { "Apples", "Oranges", "Pears", "Bananas", "Plums" }; consumption = new LinkedHashMap<String, Integer[]>(); consumption.put("Jane", new Integer[] { 3, 2, 1, 3, 4 }); consumption.put("John", new Integer[] { 2, 3, 5, 7, 6 }); consumption.put("Joe", new Integer[] { 4, 3, 3, 9, 0 }); } public static Map<String, Integer[]> getConsumption() { return consumption; } public static Double[] getAverage() { Double[] average = new Double[] { 0.0, 0.0, 0.0, 0.0, 0.0 }; for (Integer[] values : consumption.values()) { for (int i = 0; i < unitSize; i++) { average[i] += values[i]; } } for (int i = 0, size = consumption.size(); i < unitSize; i++) { average[i] = (double) (Math.round(average[i] / size * 100)) / 100; } return average; } public static Integer getSum(String person) { Integer sum = 0; for (Integer value : consumption.get(person)) { sum += value; } return sum; } public static String[] getCategories() { return categories; } }