Create your first ZK Charts"

From Documentation
Line 7: Line 7:
 
First, declare a chart component in a ZUML document. Assign <tt>type</tt> and <tt>title</tt> properties to it.
 
First, declare a chart component in a ZUML document. Assign <tt>type</tt> and <tt>title</tt> properties to it.
 
<source lang="xml">
 
<source lang="xml">
<window apply="ChartComposer">
+
    <window apply="ChartComposer">
    <charts id="chart" type="line" title="Season Average Temperature" />
+
        <charts id="chart" type="line" title="Season Average Temperature" />
</window>
+
    </window>
 
</source>
 
</source>
+
 
Then give some additional settings in composer:
+
Then specify chart data with model in the composer:
  
 
<source lang="java">
 
<source lang="java">
    // Add "°C" to value in tooltip
+
public class ChartComposer extends SelectorComposer<Window> {
    chart.getTooltip().setValueSuffix("°C");
 
  
     Legend legend = chart.getLegend();
+
     @Wire
     // Set lengend's layout and alignment
+
     Charts chart;
    legend.setLayout("vertical");
+
 
    legend.setAlign("right");
+
     public void doAfterCompose(Window comp) throws Exception {
     legend.setVerticalAlign("middle");
+
        super.doAfterCompose(comp);
    // Set lenged's border width to 0
 
    legend.setBorderWidth(0);
 
</source>
 
There has many ways to
 
And we can specify chart data with model:
 
  
<source lang="java">
+
        CategoryModel model = new SimpleCategoryModel();
    CategoryModel model = new SimpleCategoryModel();
 
  
    model.setValue("Tokyo", "Spring", new Integer(11));
+
        model.setValue("Tokyo", "Spring", new Integer(11));
    model.setValue("Tokyo", "Summer", new Integer(20));
+
        model.setValue("Tokyo", "Summer", new Integer(20));
    model.setValue("Tokyo", "Fall", new Integer(16));
+
        model.setValue("Tokyo", "Fall", new Integer(16));
    model.setValue("Tokyo", "Winter", new Integer(9));
+
        model.setValue("Tokyo", "Winter", new Integer(9));
    model.setValue("New York", "Spring", new Integer(6));
+
        model.setValue("New York", "Spring", new Integer(6));
    model.setValue("New York", "Summer", new Integer(14));
+
        model.setValue("New York", "Summer", new Integer(14));
    model.setValue("New York", "Fall", new Integer(8));
+
        model.setValue("New York", "Fall", new Integer(8));
    model.setValue("New York", "Winter", new Integer(2));
+
        model.setValue("New York", "Winter", new Integer(2));
  
    chart.setModel(model);
+
        chart.setModel(model);
 +
    }
 +
}
 
</source>
 
</source>
 +
 +
After that, you can obtain an amazing chart to visualize your data.
 +
 +
[[File:FirstChart.png]]
  
 
{{ZKChartsEssentialsPageFooter}}
 
{{ZKChartsEssentialsPageFooter}}

Revision as of 06:44, 5 March 2014

Create your first ZK Charts


WarningTriangle-32x32.png This page is under construction, so we cannot guarantee the accuracy of the content!

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

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" />
    </window>

Then specify chart data with model in the composer:

public class ChartComposer extends SelectorComposer<Window> {

    @Wire
    Charts chart;

    public void doAfterCompose(Window comp) throws Exception {
        super.doAfterCompose(comp);

        CategoryModel model = new SimpleCategoryModel();

        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(9));
        model.setValue("New York", "Spring", new Integer(6));
        model.setValue("New York", "Summer", new Integer(14));
        model.setValue("New York", "Fall", new Integer(8));
        model.setValue("New York", "Winter", new Integer(2));

        chart.setModel(model);
    }
}

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

FirstChart.png

< Get Complete Source Code of This Book >


Last Update : 2014/03/05

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