Reputation: 155
I am trying to add multiple data series to an android graph view linegraph - I am using the example from the real-time example as follows:
private DataPoint[] generateData() {
int count = 30;
DataPoint[] values = new DataPoint[count];
for (int i=0; i<count; i++) {
double x = i;
double y = Math.sin(i*0.45+2) + 0.3;
DataPoint v = new DataPoint(x, y);
values[i] = v;
}
return values;
}
and I am adding with the following:
series1 = new LineGraphSeries<DataPoint>(generateData());
graph.addSeries(series1);
however when I run this I get an NPE. Does anyone know what I am missing or doing wrong. I have removed the actual data from the generateData method to ensure that was not the problem. Any help will be much appreciated. Jack
Upvotes: 1
Views: 2464
Reputation: 3502
values = new DataPoint[10];
for (int i=0; i<10; i++) {
Integer xi = i;
Integer yi = i+1;
DataPoint v = new DataPoint(xi, yi);
values[i] = v;
}
series = new LineGraphSeries<DataPoint>(values);
graphView.addSeries(series);
Upvotes: 1
Reputation: 443
Have you added something like
<com.jjoe64.graphview.GraphView
android:layout_width="match_parent"
android:layout_height="200dip"
android:id="@+id/graph" />
to the activity's layout.If not, than add it to the activity's layout
This is where the graph is plotted.You can also change the width,height and other attributes from xml.
Upvotes: 0