我希望x轴标签如上图所示。我尝试使用AxisValueFormatter接口,但是它的作用是将标签'jh ow'从0重复到1,重复3次,而忽略了此处显示的一些标签。
这是我得到的输出。虽然图形的形状正确,但标签却不正确。
我正在共享图形数据,以便任何感兴趣的人都可以尝试制作如图所示的图形。任何帮助都会很棒,谢谢。
使用MPAndroid不重要。来自任何其他库的任何帮助也都很好。
数据为:
"lables" : ["jh ow", "n ih l", "b iy", "hh iy r", "s uw n"]
"values":[[{"x":"0.00","y":"0.00"},{"x":"0.99","y":"0.00"}],
[{"x":"0.99","y":"1.00"},{"x":"1.19","y":"0.50"}]
, [{"x":"1.19","y":"0.50"},{"x":"1.37","y":"0.50"}]
, [{"x":"1.37","y":"0.50"},{"x":"1.59","y":"0.50"}]
, [{"x":"1.59","y":"0.50"},{"x":"2.12","y":"1.00"}]]
答案 0 :(得分:0)
您只需在活动页面中列出一个简单的字符串列表;
final ArrayList<String> xVals= new ArrayList<>();
xVals.add("jh ow");
xVals.add("n ih l");
xVals.add("b iy");
xVals.add("hh iy r");
xVals.add("s uw n");
然后执行此操作;
xAxis.setValueFormatter(new MyXAxisDateArrayFormatter(xVals));
您的MyXAxisDateArrayFormatter.java
public class MyXAxisDateArrayFormatter implements IAxisValueFormatter {
private String[] mValues;
public MyXAxisDateArrayFormatter(String[] values) {
this.mValues = values;
}
@Override
public String getFormattedValue(float value, AxisBase axis) {
// "value" represents the position of the label on the axis (x or y)
return mValues[(int) value];
}
}
对我有用
答案 1 :(得分:0)
没关系,我能够通过使用旧版本的MPAndroidChart库来实现此目的,并且它像一个魅力一样工作。