package demo.bar;
import org.zkoss.chart.Charts;
import org.zkoss.chart.Legend;
import org.zkoss.chart.StackLabels;
import org.zkoss.chart.Theme;
import org.zkoss.chart.Title;
import org.zkoss.chart.YAxis;
import org.zkoss.chart.plotOptions.ColumnPlotOptions;
import org.zkoss.zk.ui.select.SelectorComposer;
import org.zkoss.zk.ui.select.annotation.Wire;
import org.zkoss.zul.Window;
public class ColumnStackedComposer extends SelectorComposer<Window> {
@Wire
Charts chart;
public void doAfterCompose(Window comp) throws Exception {
super.doAfterCompose(comp);
Title title = chart.getTitle();
title.setAlign("left");
title.setText("Major trophies for some English teams");
chart.setModel(ColumnStackedData.getCategoryModel());
YAxis yAxis = chart.getYAxis();
yAxis.setMin(0);
yAxis.getTitle().setText("Count trophies");
StackLabels stackLabels = yAxis.getStackLabels();
stackLabels.setEnabled(true);
String style = "fontWeight: bold;textOutline: 'none';";
if (!isThemeStyleSet("textColor")) {
style += "color: gray;";
}
stackLabels.setStyle(style);
Legend legend = chart.getLegend();
legend.setAlign("left");
legend.setX(70);
legend.setVerticalAlign("top");
legend.setY(70);
legend.setFloating(true);
if (!isThemeStyleSet("background2")) {
legend.setBackgroundColor("white");
}
legend.setBorderColor("#CCC");
legend.setBorderWidth(1);
legend.setShadow(false);
chart.getTooltip().setHeaderFormat("<b>{point.x}</b><br/>");
chart.getTooltip().setPointFormat("{series.name}: {point.y}<br/>Total: {point.stackTotal}");
ColumnPlotOptions plotOptions = chart.getPlotOptions().getColumn();
plotOptions.setStacking("normal");
plotOptions.getDataLabels().setEnabled(true);
}
private boolean isThemeStyleSet(String style) {
Theme theme = chart.getTheme();
return theme != null && theme.toString().contains(style);
}
}
package demo.bar;
import org.zkoss.chart.model.CategoryModel;
import org.zkoss.chart.model.DefaultCategoryModel;
public class ColumnStackedData {
private static CategoryModel model;
static {
model = new DefaultCategoryModel();
model.setValue("BPL", "Arsenal", 3);
model.setValue("BPL", "Chelsea", 5);
model.setValue("BPL", "Liverpool", 1);
model.setValue("BPL", "Manchester United", 13);
model.setValue("FA Cup", "Arsenal", 14);
model.setValue("FA Cup", "Chelsea", 8);
model.setValue("FA Cup", "Liverpool", 8);
model.setValue("FA Cup", "Manchester United", 12);
model.setValue("CL", "Arsenal", 0);
model.setValue("CL", "Chelsea", 2);
model.setValue("CL", "Liverpool", 6);
model.setValue("CL", "Manchester United", 3);
}
public static CategoryModel getCategoryModel() {
return model;
}
}