2

Basically I need to use the Graphview Api (http://www.android-graphview.org/documentation/line-graph-series-in-detail#comments) to plot some data from my highscores.

So far I can create a line graph that contains data hardcoded in, like so:

        GraphView graph = (GraphView) findViewById(R.id.graph);
    LineGraphSeries<DataPoint> series = new LineGraphSeries<DataPoint>(new DataPoint[] {
            // date then score
            new DataPoint(0, 1),
            new DataPoint(1, 5),
            new DataPoint(2, 3),
            new DataPoint(3, 2),
            new DataPoint(2, 2)
    });
    graph.addSeries(series);

However my data is stored in 2 arraylists

    final ArrayList<Date>date = new ArrayList<Date>();
    final ArrayList<BigDecimal> score= new ArrayList<BigDecimal>();

I would like to plot the graph using the dates as the horizontal axis and the score as the vertical.

I've never used graphview before and I'm struggling to grasp how to use it effectively .

Any help would be great Thanks

Rhys Drury
  • 305
  • 2
  • 20

1 Answers1

0

This is an example from my project

barGraph.getGridLabelRenderer().setLabelFormatter(new DateAsXAxisLabelFormatter(context));

Of course you have to convert your data source first as follows:

        DataPoint[] volumeDataPoints = new DataPoint[graphDots.size()];
        int i = 0 ;
        for(MainGraphDot gd :  graphDots){
            volumeDataPoints[i] = new DataPoint(gd.getDate(),gd.getV());
            i++;
        }

DataPoint is the accepted arraytype for graphView. You can directly set Date objects as X values, BigDecimal values are the Y values.

Note: DateAsXAxisLabelFormatter can also get DateFormat as second parameter to its constructor so that you can change the format of your date values.

http://jjoe64.github.io/GraphView/javadoc/com/jjoe64/graphview/helper/DateAsXAxisLabelFormatter.html

Oguz Ozcan
  • 1,694
  • 19
  • 26