Install Android Android Y-Axis for Beginners

I am using the MPAndroid library to draw a line chart. Everything works fine except for the starting point of the Y-axis. I have 0 record for Y for the first two records of X, and then for the third record I have some value, the graph starts from the 0.0 location, not directly from the third point. I want the chart to start from the third point.

How can i do this?

Also, the 0 axis is displayed on the Y axis, tried to delete it, but could not find a solution. I tried leftAxis.setStartAtZero(false);, but it does not remove the 0 mark on the Y axis, and also includes a blur line at this point, which seems to be part of the graph

+4
source share
1 answer

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

  • Limit the y axis to your value. (User will not be able to scroll below this point)

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

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

To remove the "0" from the Y axis, you must 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 "";
    }
}
+6
source

All Articles