Using Series"

From Documentation
(Created page with "{{ZKChartsEssentialsPageHeader}} __TOC__ Another way to add data to a chart is through <javadoc directory="zkcharts">org.zkoss.chart.Series</javadoc>. You have to use <tt>Seri...")
 
Line 11: Line 11:
 
...
 
...
 
Series series0 = chart.getSeries(0);
 
Series series0 = chart.getSeries(0);
 +
...
 +
Series series1 = chart.getSeries(1);
 
</source>
 
</source>
 +
 +
Call <tt>setData()</tt> to add data points to the series, and data could be Double, Integer, Number. If you want to show category, pass <javadoc directory="zkcharts">org.zkoss.chart.Point</javadoc> as parameters.
 +
 +
Here is a simple example.
 +
 +
<source lang='java' high='13,14,15,16'>
 +
public class SeriesComposer extends SelectorComposer<Window> {
 +
 +
    @Wire
 +
    Charts chart;
 +
   
 +
    public void doAfterCompose(Window comp) throws Exception {
 +
        super.doAfterCompose(comp);
 +
        initData();
 +
    }
 +
 +
private void initData() {
 +
chart.getXAxis().setType("category");
 +
Series series0 = chart.getSeries(0);
 +
series0.setData(new Point("apples", 5), new Point("pears", 9), new Point("oragnes", 4), new Point("bannas", 8), new Point("grapes", 10));
 +
series0.setType("area");
 +
series0.setName("John");
 +
 +
Series series1 = chart.getSeries(1);
 +
series1.setData(new Point("apples", 2),  new Point("pears", 1),new Point("oragnes", 3), new Point("bannas", 5), new Point("grapes", 9));
 +
series1.setType("column");
 +
series1.setName("Peter");
 +
}
 +
}
 +
</source>
 +
* Line 14: If there is missing points, just pass null like <tt>new Point("category", null)</tt>
  
  
 
{{ZKChartsEssentialsPageFooter}}
 
{{ZKChartsEssentialsPageFooter}}

Revision as of 06:53, 12 April 2017



Another way to add data to a chart is through Series. You have to use Series to combine multiple types of chart in one chart component like this demo because each Series can be rendered as different chart types.

You don't need to instantiate Series by yourselves, just call getSeries(index) like:

Charts chart;
...
Series series0 = chart.getSeries(0);
...
Series series1 = chart.getSeries(1);

Call setData() to add data points to the series, and data could be Double, Integer, Number. If you want to show category, pass Point as parameters.

Here is a simple example.

public class SeriesComposer extends SelectorComposer<Window> {

    @Wire
    Charts chart;
    
    public void doAfterCompose(Window comp) throws Exception {
        super.doAfterCompose(comp);
        initData();
    }

	private void initData() {
		chart.getXAxis().setType("category");
		Series series0 = chart.getSeries(0);
		series0.setData(new Point("apples", 5), new Point("pears", 9), new Point("oragnes", 4), new Point("bannas", 8), new Point("grapes", 10));
		series0.setType("area");
		series0.setName("John");
		
		Series series1 = chart.getSeries(1);
		series1.setData(new Point("apples", 2),  new Point("pears", 1),new Point("oragnes", 3), new Point("bannas", 5), new Point("grapes", 9));
		series1.setType("column");
		series1.setName("Peter");
	}
}
  • Line 14: If there is missing points, just pass null like new Point("category", null)


< Get Complete Source Code of This Book >


Last Update : 2017/04/12

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