如何控制 LineDataSet 上标签的频率?

How do I control the frequency of labels on LineDataSet?

在 MPAndroidChart 中,我可以使用 setSkipLabels 控制 xaxis 值的频率。但是,这只会影响 x 轴。我如何对折线图中的线条本身执行相同的操作?

我不认为该库提供了一种巧妙的方法来为 LineDataSet 和 X 轴执行此操作。 恕我直言,最好的办法是根据需要使用 custom ValueFormatter 将文本设置为空白。

示例显示十分之一的标签:

public class MyValueFormatter implements ValueFormatter {

    private DecimalFormat mFormat;

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

    @Override
    public String getFormattedValue(float value, Entry entry, int dataSetIndex, ViewPortHandler viewPortHandler) {
        String output = "";
        if (entry.getXIndex() % 10 == 0) output = mFormat.format(value);
        return output;
    }
}

然后,将格式化程序附加到数据集

lineDataSet.setValueFormatter(new MyValueFormatter()); 

这只会影响图中每个值旁边显示的文本。

您还可以禁用在每个值上绘制圆圈:

lineDataSet.setDrawCircles(false);