2

How can I make my GraphView always start on zero and not on the lowest number of my data ? For example if my data received is {10,44,1,15}, the bottom one will be the 1 and I wanted to be zero. How can I do that ?

And how can I make the GraphViewSeries dynamically ? For example I receive an array with data and I want depending the size of the array to make the GraphViewSeries, like if I receive an array with 3 elements the GraphViewSeries will be like this:

GraphViewSeries exampleSeries = new GraphViewSeries(
                new GraphViewData[] { 
                        new GraphViewData(1, total[0]),
                        new GraphViewData(2, total[1]),
                        new GraphViewData(3, total[2])});

If the array has 5 elements with would be like this:

GraphViewSeries exampleSeries = new GraphViewSeries(
                new GraphViewData[] { 
                        new GraphViewData(1, total[0]),
                        new GraphViewData(2, total[1]),
                        new GraphViewData(3, total[2]),
                        new GraphViewData(4, total[3]),
                        new GraphViewData(5, total[4]) });

How can I do this ?

SnakeSheet
  • 151
  • 2
  • 10

2 Answers2

5

You can set the min and max values like this:

GraphView graphView = new LineGraphView(context, "Graph name")
graphView.setManualYAxisBounds((double) max, (double) min);

For dynamic series you can do this:

GraphViewData[] data = new GraphViewData[total.length];
for (int a = 0; a < total.length; a++) {
    data[a] = new GraphView.GraphViewData(a, total[a]);
}

then you add your data to a series like this:

GraphViewSeriesStyle style = new GraphViewSeriesStyle(Color.rgb(150, 150, 150), 2);
GraphViewSeries series = new GraphViewSeries(driverName.substring(0, 3).toUpperCase(), style, data);

for the official documentation refer to here.

Ayoub
  • 341
  • 1
  • 13
5

In GraphView 4.x, setting the axis min and max values has to be done via the viewport:

graphView.getViewport().setYAxisBoundsManual(true);
graphView.getViewport().setMinY(min);
graphView.getViewport().setMaxY(max);

'graphView.setManualYAxisBounds()' no longer exists.

See also http://www.android-graphview.org/documentation/migration-from-31-to-40

jox
  • 2,218
  • 22
  • 32