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

时间:2016-04-23 11:20:57

标签: mpandroidchart

在MPAndroidChart中,我可以使用setSkipLabels控制xaxis值的频率。但是,这只会影响xaxis。如何在折线图中对线条本身做同样的事情?

1 个答案:

答案 0 :(得分:1)

我不认为库为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;
    }
}

然后,将格式化程序附加到DataSet

lineDataSet.setValueFormatter(new MyValueFormatter()); 

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

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

lineDataSet.setDrawCircles(false);
相关问题