Using Series"

From Documentation
Line 6: Line 6:
 
Another way to add data to a chart is through <javadoc directory="zkcharts">org.zkoss.chart.Series</javadoc>. You have to use <tt>Series</tt> to combine multiple types of chart in one chart component like [https://www.zkoss.org/zkchartsdemo/combo this demo] because each <tt>Series</tt> can be rendered as different chart types.
 
Another way to add data to a chart is through <javadoc directory="zkcharts">org.zkoss.chart.Series</javadoc>. You have to use <tt>Series</tt> to combine multiple types of chart in one chart component like [https://www.zkoss.org/zkchartsdemo/combo this demo] because each <tt>Series</tt> can be rendered as different chart types.
  
You don't need to instantiate <tt>Series</tt> by yourselves, just call <tt>getSeries(index)</tt> like:
+
You don't need to instantiate <tt>Series</tt> by yourselves, just call <tt>getSeries(index)</tt> and its underlying implementation creates for you:
 
<source lang='java'>
 
<source lang='java'>
 
Charts chart;
 
Charts chart;

Revision as of 06:56, 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) and its underlying implementation creates for you:

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.

SeriesComposer.java

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.