<?xml version="1.0" encoding="UTF-8"?>
<window apply="demo.area.AreaStackedComposer">
<charts id="chart" type="area"
title="Greenhouse gases from Norwegian economic activity" />
</window>
package demo.area;
import java.util.Map;
import org.zkoss.chart.AxisTitle;
import org.zkoss.chart.Charts;
import org.zkoss.chart.Series;
import org.zkoss.chart.plotOptions.AreaPlotOptions;
import org.zkoss.zk.ui.select.SelectorComposer;
import org.zkoss.zk.ui.select.annotation.Wire;
import org.zkoss.zul.CategoryModel;
import org.zkoss.zul.SimpleCategoryModel;
import org.zkoss.zul.Window;
public class AreaStackedComposer extends SelectorComposer<Window> {
@Wire
Charts chart;
public void doAfterCompose(Window comp) throws Exception {
super.doAfterCompose(comp);
chart.setSubtitle("Source: " +
"<a href=\"https://www.ssb.no/en/statbank/table/09288/\"" +
"target=\"_blank\">SSB</a>");
int seriesIndex = 0;
for (Map.Entry<String, Integer[]> data: AreaStackedData.getData()
.entrySet()) {
Series series = chart.getSeries(seriesIndex++);
series.setName(data.getKey());
series.setData(data.getValue());
}
AxisTitle title = chart.getYAxis().getTitle();
title.setUseHTML(true);
title.setText("Million tonnes CO<sub>2</sub>-equivalents");
chart.getTooltip().setShared(true);
chart.getTooltip().setHeaderFormat("<span style=\"font-size:12px\"><b>{point.key}</b></span><br>");
chart.getPlotOptions().getSeries().setPointStart(2012);
AreaPlotOptions plotOptions = chart.getPlotOptions().getArea();
plotOptions.setStacking("normal");
plotOptions.setLineColor("#666666");
plotOptions.setLineWidth(1);
plotOptions.getMarker().setLineWidth(1);
plotOptions.getMarker().setLineColor("#666666");
}
}
package demo.area;
import java.util.LinkedHashMap;
import java.util.Map;
import org.zkoss.chart.model.CategoryModel;
import org.zkoss.chart.model.DefaultCategoryModel;
public class AreaStackedData {
private static final Map<String, Integer[]> data;
static {
data = new LinkedHashMap<>();
data.put("Ocean transport", new Integer[] {
13234, 12729, 11533, 17798, 10398, 12811, 15483, 16196, 16214
});
data.put("Households", new Integer[] {
6685, 6535, 6389, 6384, 6251, 5725, 5631, 5047, 5039
});
data.put("Agriculture and hunting", new Integer[] {
4752, 4820, 4877, 4925, 5006, 4976, 4946, 4911, 4913
});
data.put("Air transport", new Integer[] {
3164, 3541, 3898, 4115, 3388, 3569, 3887, 4593, 1550
});
data.put("Construction", new Integer[] {
2019, 2189, 2150, 2217, 2175, 2257, 2344, 2176, 2186
});
}
public static Map<String, Integer[]> getData() {
return data;
}
}