Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/196.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何更改MPAndroidchart中Y轴标签的间距?_Android_Mpandroidchart - Fatal编程技术网

如何更改MPAndroidchart中Y轴标签的间距?

如何更改MPAndroidchart中Y轴标签的间距?,android,mpandroidchart,Android,Mpandroidchart,我如何使我的YAxis标签以一个间隙升高,即从下图所示的给定值开始?如果尝试使用偏移,则会使YAxis标签值与Y轴数据不正确地对应 以下是我目前的代码: public void setChartProperties() { YAxis rightAxis = chart.getAxisRight(); YAxis leftAxis = chart.getAxisLeft(); XAxis xAxis = chart.getXAxis();

我如何使我的YAxis标签以一个间隙升高,即从下图所示的给定值开始?如果尝试使用偏移,则会使YAxis标签值与Y轴数据不正确地对应

以下是我目前的代码:

  public void setChartProperties() {
        YAxis rightAxis = chart.getAxisRight();
        YAxis leftAxis = chart.getAxisLeft();
        XAxis xAxis = chart.getXAxis();
        chart.getLegend().setEnabled(false);
        chart.getDescription().setEnabled(false);
        chart.setDrawBorders(false);
        chart.setPinchZoom(false);
        chart.setAutoScaleMinMaxEnabled(true);
        chart.setExtraOffsets(0, 0, 0, 0);
        xAxis.setLabelCount(6, true);
        xAxis.setGranularity(1f);
        xAxis.setDrawGridLines(false);
        xAxis.setPosition(XAxisPosition.BOTTOM);
        xAxis.setAvoidFirstLastClipping(true);
        leftAxis.setPosition(YAxisLabelPosition.INSIDE_CHART);
        leftAxis.setDrawLabels(true);
        leftAxis.setSpaceBottom(60);
        leftAxis.setDrawGridLines(true);
        leftAxis.setLabelCount(3, true);
        leftAxis.setCenterAxisLabels(true);
        leftAxis.setDrawGridLines(false);
        rightAxis.setEnabled(false);
        xAxis.setAvoidFirstLastClipping(true);
        dataSet.setColor(R.color.graphLineColor);
    }
这是我的图表的截图


这是通过实现
IAxisValueFormatter
实现的,因为我想保留所有值,只需修改标签:

public class MyValueFormatter implements IAxisValueFormatter {

    private final float cutoff;
    private final DecimalFormat format;

    public MyValueFormatter(float cutoff) {
        this.cutoff = cutoff;
        this.format = new DecimalFormat("###,###,###,##0.00");
    }

    @Override
    public String getFormattedValue(float value, AxisBase axis) {
        if (value < cutoff) {
            return "";
        }

        return "$" + format.format(value);
    }
}
其中,
yMin
是先前定义的:

private float yMin = 0; 
然后分配图表的最小Y值


到目前为止有代码吗?在上面添加了代码。谢谢你的意思是你只是想让标签显示高于某个级别的Y值?所以不要显示所有的标签,对吗?谢谢你的回复。在上面和下面,我想复制上面的蓝色图片。我使用leftAxis.setSpaceBottom(60);为了让我的YAxis数据从底部开始60f,但我还没有复制上面的3个标签。我还尝试了leftAxis.setLabelCount(3,true);,但库决定标签的间距和值(如上图所示)。
private float yMin = 0;