0

I am using the Graph View library to plot graph in Android. I would like to plot a audiogram. Anyone know how to make the Y axis growing downwards and also set the horizontal title above the graph?

mach
  • 8,315
  • 3
  • 33
  • 51

1 Answers1

0

First part is relatively simple; start by creating your own set of Y-labels by emulating the existing library logic but storing the values in reverse order into your own String Array. Then simply multiply all your Y values by -1, to make them negative, and set the graphview to use your own labels that mask their negativity eg.

    Double yMin = Math.floor(...);
    Double yMax = Math.ceil(...);

    int yLabelsCnt = 1 + (int)(Math.ceil(yMaxValue) - yMin.intValue());
    int yLabelInterval = (int)(Math.ceil((double)yLabelsCnt / MAX_Y_LABELS));
    yLabelsCnt = (yLabelInterval > 1)
              ? (int)Math.ceil(yLabelsCnt / yLabelInterval) 
              : yLabelsCnt;

    // Y labels
    String[] yArray = new String[ yLabelsCnt ];
    int j=yLabelsCnt-1;
    for(int i = yMin.intValue(); i < (yMin.intValue() + (yLabelInterval * yLabelsCnt)); i+=yLabelInterval){
        yArray[j--]=i.toString();
    }

    ....

    // invert the Y values
    for (DataObjects myObject : myDataObjects) {
        lineGraphSeries.appendData( new DataPoint(myObject.getValueX(), (myObject.getValueY() * -1.0 )),
                    true,
                    MAX_DATA_POINTS);
    }

    ....

    staticLabelsFormatter.setVerticalLabels(yArray);
    graphView.getGridLabelRenderer().setLabelFormatter(staticLabelsFormatter);
arober11
  • 1,969
  • 18
  • 31