如何在mpandroidchart中设置xlabels和ylabels的值 [英] how to set values for xlabels and ylabels in mpandroidchart

查看:563
本文介绍了如何在mpandroidchart中设置xlabels和ylabels的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用mpandroidchart android库.我正在执行折线图.我可以在这里自行设置x和y标签吗?当前,它正在基于提供给图表的数据集添加值.您能对此提供一些想法吗?

I am using mpandroidchart android library. I am implementing line charts. Here can i set the x and y labels on my own? currently it is adding the values based on the dataset provided to the chart. Can you please give some idea on this?

推荐答案

您必须在轴对象上使用格式化程序.

You have to use a formatter on your axis object.

有两种格式化程序XAxisValueFormatter和YAxisValueFormatter.

There is two kind of formatter XAxisValueFormatter and YAxisValueFormatter.

这是我用来将带有后缀"h"的X标签号更改几个小时的代码:

This the code i used to change the X label number with suffix "h" for hours :

//get reference on chart line view
LineChart chart = (LineChart) pActivity.findViewById(R.id.chart);
//set formater for x Label
chart.getXAxis().setValueFormatter(new XAxisValueFormatter() {

        @Override
        public String getXValue(String original, int index, ViewPortHandler viewPortHandler) {
            //return number + "h" here
            // but you can do everything you want here. The string returned will be displayed on chart x label
            return original + "h";
        }
    });
//axis to the bottom
chart.getXAxis().setPosition(XAxisPosition.BOTTOM);
//populate with data
chart.setData(data);
// refresh
chart.invalidate();

这篇关于如何在mpandroidchart中设置xlabels和ylabels的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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