javaandroidandroid-graphview

This line of code is supposed to draw a graph. But it is not plotting anything. It is just showing the axes


I'm using jjoe64 graphview library //Draws Graph

GraphView graph = findViewById(R.id.plot);
graph.setVisibility(View.VISIBLE);
DataPoint[] data = new DataPoint[term];
for (int i=0;i<term;i++){
   data[i] = new DataPoint(i+1,P * java.lang.Math.pow(1 + (r) / 100, i));
}
LineGraphSeries<DataPoint> series = new LineGraphSeries<>(data);
graph.addSeries(series);

Solution

  • The following code fixed it:

    graph.removeAllSeries();
        LineGraphSeries<DataPoint> series = new LineGraphSeries<>();
    
        for (int i=1;i<=term;i++){
            int x=i;
            long y=Math.round(P * java.lang.Math.pow(1 + (r) / 100, i));
            series.appendData(new DataPoint(x,y),true,term);
        }
    
        graph.addSeries(series);