【发布时间】:2014-11-21 12:49:20
【问题描述】:
我正在使用 mpandroidchart android 库。我正在实施折线图。在这里我可以自己设置 x 和 y 标签吗?目前它正在根据提供给图表的数据集添加值。能不能给点意见?
【问题讨论】:
我正在使用 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();
【讨论】:
你能说得更具体点吗?对于 x-labels,您可以在您提供的数据对象中设置您想要的任何内容。对于 y 标签,请调用 setYRange(...) 设置要显示的固定值范围。
【讨论】: