package zk.support; import org.zkoss.bind.annotation.BindingParam; import org.zkoss.bind.annotation.Command; import org.zkoss.bind.annotation.Init; import org.zkoss.bind.annotation.NotifyChange; import org.zkoss.chart.plotOptions.AreaPlotOptions; import org.zkoss.zul.CategoryModel; import org.zkoss.zul.SimpleCategoryModel; /** * Date: 17.03.14 */ public class ChartsTestVM { private CategoryModel model = null; private String dataParam = "series"; private char seriesPrefix = 'A'; @Init public void init() { doReplaceModel(); } @Command("configurePlot") public void doConfigurePlot(@BindingParam("areaPlotOptions") AreaPlotOptions plotOptions) { plotOptions.setStacking("normal"); } @Command("replaceModel") @NotifyChange({"model"}) public void doReplaceModel() { model = new SimpleCategoryModel(); retrieveDataFromDB(dataParam); } @Command("updateModel") public void doUpdateModel() { model.clear(); retrieveDataFromDB(dataParam); } private void retrieveDataFromDB(String dataParam) { //simulates model population for(int index = 0; index < 3; index++) { model.setValue(seriesPrefix + dataParam + " 1", "val" + index, Double.valueOf(Math.random() * 100)); model.setValue(seriesPrefix + dataParam + " 2", "val" + index, Double.valueOf(Math.random() * 100)); model.setValue(seriesPrefix + dataParam + " 3", "val" + index, Double.valueOf(Math.random() * 100)); model.setValue(seriesPrefix + dataParam + " 4", "val" + index, Double.valueOf(Math.random() * 100)); } seriesPrefix++; } public CategoryModel getModel() { return model; } }