我正在使用 mpandroidchart android 库。我正在实施折线图。这里我可以自己设置x和y标签吗?目前,它正在根据提供给图表的数据集添加值。您能对此提供一些想法吗?
您必须在轴对象上使用格式化程序。
有两种格式化程序 XAxisValueFormatter 和 YAxisValueFormatter。
这是我用来更改后缀“h”的 X 标签编号的代码:
//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();
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)