Question

i test the android-graphview library and i find this behavior: I use the latest GraphViewDemos and the first SimpleGraph example. It shows a linegraph with the correct data. (The y-axis values are 1,2,3)

GraphViewSeries exampleSeries = new GraphViewSeries(new GraphViewData[] {
            new GraphViewData(1, 2.0d)
            , new GraphViewData(2, 1.5d)
            , new GraphViewData(2.5, 3.0d) // another frequency
            , new GraphViewData(3, 2.5d)
            , new GraphViewData(4, 1.0d)
            , new GraphViewData(5, 3.0d)
    });

The max value is three (Sorry i can't post an image) and all other coordinates are correct.

If i add these lines

graphView.getGraphViewStyle().setNumVerticalLabels(5);
graphView.setVerticalLabels( new String[]{"4","3","2","1","0"});

before

LinearLayout layout = (LinearLayout) findViewById(R.id.graph1);
layout.addView(graphView);

in the code to change the y-axis, i get a graph where the max-value is not still three, it's four. And all the other coordinates are wrong in the y-values.

Why does the complete graph change and not only the y-axis?

Was it helpful?

Solution

with the line:

graphView.setVerticalLabels( new String[]{"4","3","2","1","0"});

you set static labels to the graph. So the vertical labels (y-values) have no link to the data anymore.

This line is for dynamic labels. You can modify the count of the labels that will be generated.

graphView.getGraphViewStyle().setNumVerticalLabels(5);

But you are using static labels, so the line doesn't make sense.

OTHER TIPS

http://android-graphview.org/

Visit this page and scroll to the Custom Label Formatter part of the tutorial.

GraphView graphView = new LineGraphView(this, "example");
graphView.setCustomLabelFormatter(new CustomLabelFormatter() {
  @Override
public String formatLabel(double value, boolean isValueX) {
  if (isValueX) {
     if (value < 5) {
        return "small";
     } else if (value < 15) {
        return "middle";
     } else {
        return "big";
     }
  }
    return null; // let graphview generate Y-axis label for us
}
   });

Basically you will have to map the actual y value with the static Vertical Label you have provided

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top