From Documentation

Jump to: navigation, search

In this section we will show how to create your first ZK Charts component step by step.


A Very Basic Chart

First, declare a chart component in a ZUML document. Assign type and title properties to it.


    <window apply="ChartComposer">
        <charts id="chart" type="line" title="Season Average Temperature" />

Use model to handle chart data, and set model to chart in a Controller which extends SelectorComposer

public class ChartComposer extends SelectorComposer<Window> {

    Charts chart;

    public void doAfterCompose(Window comp) throws Exception {

        // Create a predefined implementation category model
        CategoryModel model = new DefaultCategoryModel();

        // Set value to the model
        model.setValue("Tokyo", "Spring", new Integer(11));
        model.setValue("Tokyo", "Summer", new Integer(20));
        model.setValue("Tokyo", "Fall", new Integer(16));
        model.setValue("Tokyo", "Winter", new Integer(-2));
        model.setValue("New York", "Spring", new Integer(6));
        model.setValue("New York", "Summer", new Integer(12));
        model.setValue("New York", "Fall", new Integer(10));
        model.setValue("New York", "Winter", new Integer(2));

        // Set model to the chart

After that, you can easily obtain an amazing chart to visualize your data.


Change Configuration

Moreover, if you want to change the configuration, you can add additional declarations in the composer:

    // Get the legend option in chart
    Legend legend = chart.getLegend();

    // Chage lengend's layout to vertical

    // Change lengend's alignment

    // Remove lenged's border

The Legend of chart will be moved to the right of the chart without border.


Copyright © Potix Corporation. This article is licensed under GNU Free Documentation License.