Revision history [back]

click to hide/show revision 1
initial version

answered 2020-08-31 15:29:18 +0800

cor3000 gravatar image cor3000

ZK Team

the following works using ZK 9.1.0 and ZKCharts 7.2.1.1

Zul:

<zk>
    <charts width="400" height="300" title="test" apply="ChartComposer_11556"/>
</zk>

Java:

import org.zkoss.chart.Charts;
import org.zkoss.chart.model.DefaultCategoryModel;
import org.zkoss.chart.plotOptions.LinePlotOptions;
import org.zkoss.zk.ui.util.Composer;

public class ChartComposer_11556 implements Composer<Charts> {
    @Override
    public void doAfterCompose(Charts chart) throws Exception {
        chart.setType(Charts.LINE);
        DefaultCategoryModel model = new DefaultCategoryModel();
        model.setValue("Pork", "2018", 25.3);
        model.setValue("Pork", "2019", 19.2);
        model.setValue("Pork", "2020", 30);
        model.setValue("Beef", "2018", 74.7);
        model.setValue("Beef", "2019", 80.8);
        model.setValue("Beef", "2020", 70);
        chart.setModel(model);
        LinePlotOptions linePlotOptions = chart.getPlotOptions().getLine();
        linePlotOptions.getDataLabels().setFormat("{y}%");
        linePlotOptions.getDataLabels().setEnabled(true);
    }
}

Result:

image description

the following works using ZK 9.1.0 and ZKCharts 7.2.1.1

Zul:

<zk>
    <charts width="400" height="300" title="test" apply="ChartComposer_11556"/>
apply="ChartComposer"/>
</zk>

Java:

import org.zkoss.chart.Charts;
import org.zkoss.chart.model.DefaultCategoryModel;
import org.zkoss.chart.plotOptions.LinePlotOptions;
import org.zkoss.zk.ui.util.Composer;

public class ChartComposer_11556 ChartComposer implements Composer<Charts> {
    @Override
    public void doAfterCompose(Charts chart) throws Exception {
        chart.setType(Charts.LINE);
        DefaultCategoryModel model = new DefaultCategoryModel();
        model.setValue("Pork", "2018", 25.3);
        model.setValue("Pork", "2019", 19.2);
        model.setValue("Pork", "2020", 30);
        model.setValue("Beef", "2018", 74.7);
        model.setValue("Beef", "2019", 80.8);
        model.setValue("Beef", "2020", 70);
        chart.setModel(model);
        LinePlotOptions linePlotOptions = chart.getPlotOptions().getLine();
        linePlotOptions.getDataLabels().setFormat("{y}%");
        linePlotOptions.getDataLabels().setEnabled(true);
    }
}

Result:

image description

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