Menu

Create single line series chart

Perform the following steps to create a single line series chart.

1. Create a data set of XYSeries coordinates as follows:

  • Create the instance of XYMultipleSeriesDataset and then create XYSeries instance.
  • Add the X and Y values using this instance.
  • Once the X and Y coordinates are added to XYSeries, add the XYSeries instance to the XYMultipleSeriesDataset instance.
XYMultipleSeriesDataset mDataset = new XYMultipleSeriesDataset();
XYSeries series1 = new XYSeries("XYZ");
series1.add(1, 100);
series1.add(2, 150);
series1.add(3, 50);
series1.add(4, 25);
series1.add(5, 70); 
mDataset.addSeries(series1);

2. Create render style configuration for each XYSeries that is added in the dataset as follows:

  • Create the instance of XYMultipleSeriesRenderer and then create XYSeriesRenderer instance.
  • Using XYSeriesRenderer instance, configure the style. Refer the EDU SDK Javadoc for different style configurations.
  • Add XYSeriesRenderer instance to the instance of XYMultipleSeriesRenderer.
XYMultipleSeriesRenderer mRenderer = new XYMultipleSeriesRenderer();
XYSeriesRenderer renderer1 = new XYSeriesRenderer();
renderer1.setColor(Color.GREEN);
renderer1.setPointStyle(PointStyle.CIRCLE);
renderer1.setFillPoints(true);
renderer1.setLineWidth(2F);
renderer1.setDisplayChartValues(true);

mRenderer.addSeriesRenderer(renderer1);

3. Use the chart factory method to create the line chart.

View v = ChartFactory.getLineChartView(getActivity(), mDataset, mRenderer);

4. Add the returned graph view to your app’s view group for display.

Output