Quick Start Guide

Adding a Series

Now you have your chart it’s time to add some data. Adding data to a ShinobiChart is as simple as creating a DataAdapter, adding data to it and handing it to a series on the chart. For this app you’ll have 2 series, each with its own data adapter. Still inside the if statement add:

SimpleDataAdapter<Double, Double> dataAdapter1 = new SimpleDataAdapter<Double, Double>();
SimpleDataAdapter<Double, Double> dataAdapter2 = new SimpleDataAdapter<Double, Double>();

This creates a new SimpleDataAdapter - it notifies the chart every time a data point/set of data points is added or removed, and is supplied out the box.

Now, add some data to it - sine waves

for (int i = 0; i < 100; i++) {
    double radians = i * Math.PI / 25.0;
    dataAdapter1.add(new DataPoint<Double, Double>(radians, Math.sin(radians)));
    dataAdapter2.add(new DataPoint<Double, Double>(radians, Math.cos(radians)));

A DataPoint has an X and a Y value and is parametrized by the types of those X and Y values. Like SimpleDataAdapter it’s supplied out the box for when you just need a simple data point representation. You can instead create your own data points by implementing the Data interface. Here you are using Double, but the types should be appropriate for their intended axes. NumberAxis is compatible with any numeric data which is representable using java.lang.Number or its subclasses, and will accept Data objects parametrized to those types.

Next, create 2 line series and give the data adapters to them. Finally, give them to the chart.

LineSeries series1 = new LineSeries();

LineSeries series2 = new LineSeries();

Excellent, you now have your first ShinobiChart complete with data. But don’t go anywhere just yet, you still need to style the chart a bit to make it a little bit more exciting.

Tip: Some devices have to be told that the application requires hardware acceleration in order to display a chart. Simply add android:hardwareAccelerated="true" to the application element of the AndroidManifest.xml file in the ShinobiQuickStart project.

<< Previous: Draw a Simple Chart | Next: Basic Styling >>