如何使用MPAndroidChart设置X轴标签 [英] How to set the x-axis label with MPAndroidChart

查看:1273
本文介绍了如何使用MPAndroidChart设置X轴标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将MPAndroidChart用于我的应用,如下所示:

I use MPAndroidChart for my app like this:

但是我不能添加这样的标签

but I can not add tag like that

推荐答案

是否需要您的标记,而不是那些?

Do you need your tag instead of those values?

如果是这样,那么这里就是这样做的方法.

If so, then here it goes the method to do so.

XAxis标签添加到ArrayList

    final ArrayList<String> xLabel = new ArrayList<>();
    xLabel.add("9");
    xLabel.add("15");
    xLabel.add("21");
    xLabel.add("27");
    xLabel.add("33");  

    // or use some other logic to save your data in list. For ex. 
    for(i=1; i<50; i+=2)
    { 
       xLabel.add(""+3*i);
    }

然后在setValueFormatter中使用此标签.
例如:

then use this label in the setValueFormatter.
Ex:

    XAxis xAxis = mChart.getXAxis();
    xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
    xAxis.setDrawGridLines(false);
    xAxis.setValueFormatter(new IAxisValueFormatter() {
        @Override
        public String getFormattedValue(float value, AxisBase axis) {
            return xLabel.get((int)value);
        }
    });

结果:

这篇关于如何使用MPAndroidChart设置X轴标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆