设置 MP Android Y 轴起始点为 Android

5
我正在使用MPAndroid库来绘制折线图。除了Y轴起始点之外,一切正常。我在前两个X轴入口处有Y的0入口,然后在第三个入口处有一些值,图表从0,0位置开始绘制而不是直接从第三个点开始。我希望图表能够从第三个点开始绘制。
我该怎么做呢?
此外,在Y轴上显示0标签,尝试将其删除但没有找到解决方案。尝试使用leftAxis.setStartAtZero(false);但它不能删除Y轴上的0标签,并且还包括一个模糊线条。

您想将视图移动到第三个点吗? - Dhruv
请展示你的代码。 - Philipp Jahoda
是的,我想把它移动到第三个点。 - unflagged.destination
1个回答

7
从文档中,这里这里,我认为您有两种方法可以绘制您想要的内容。
  • 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)
    
要从 Y 轴中删除“0”,您应该使用自定义的 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 "";
    }
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接