Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set MP Android Y-Axis start point android

I am using MPAndroid library for rendering line chart. Everything works fine except the starting point of Y-Axis. I have 0 entry for Y for first two X entries and then for third entry I have some value, Graph start drawing from 0,0 location and not directly from third point. I want graph to start from third point.

How can I do that?

Also on Y axis 0 label is shown, Tried to remove that but couldn't find solution. Tried leftAxis.setStartAtZero(false); but it doesn't remove 0 label on Y axis and also include a blur line on that point which seems as part of graph

like image 708
unflagged.destination Avatar asked Apr 13 '16 07:04

unflagged.destination


1 Answers

From the documentation, here and here, I think you have two ways to draw what you want.

  • Limit your Y axis to your value. (User won't be able to scroll below this point)

    yourChart.getAxisLeft().setAxisMinValue(yourValue);
    
  • Modify ViewPort to fit your needs:

    yourChart.moveViewToY(valueCenterOfScreen, YAxis.AxisDependency.LEFT)
    

To remove '0' from your Y Axis, you should use a custom YAxisValueFormatter:

    public class MyYAxisValueFormatter implements YAxisValueFormatter {

    private DecimalFormat mFormat;

    public MyYAxisValueFormatter () {
        mFormat = new DecimalFormat("###,###,##0.0"); // use one decimal
    }

    @Override
    public String getFormattedValue(float value, YAxis yAxis) {
        if (value != 0)
            return mFormat.format(value);
        else
            return "";
    }
}
like image 164
00seb Avatar answered Nov 02 '22 18:11

00seb