how to set values for xlabels and ylabels in mpandroidchart

我的未来我决定 提交于 2019-12-06 14:05:42

You have to use a formatter on your axis object.

There is two kind of formatter XAxisValueFormatter and YAxisValueFormatter.

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();

Could you be more specific? For the x-labels you can set whatever you want in the data object you provide. For the y-labels, call setYRange(...) to set a fixed range of values to show.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!