1、当X轴的Position设置为Button时,X轴的数字会两个显示一个
此时只要设置 xAxis.setGranularity(1f)就可以了
2、第一个柱形只显示一半
那是因为设置了xAxis.setAxisMinimum(0);Y轴可以这么设置,X轴从零开始的话还是设置默认好了
3、X轴显示的自定义
X轴先传入正常的数字
List<BarEntry> barEntries = new ArrayList<>();
barEntries.add(new BarEntry(0,88));
barEntries.add(new BarEntry(1,52));
barEntries.add(new BarEntry(2,48));
barEntries.add(new BarEntry(3,66));
barEntries.add(new BarEntry(4,37));
barEntries.add(new BarEntry(5,82));
barEntries.add(new BarEntry(6,0));
BarDataSet barDataSet = new BarDataSet(barEntries,"");
然后创建string类型的list
List<String> strings = new ArrayList<>();
strings.add("周一");
strings.add("周二");
strings.add("周三");
strings.add("周四");
strings.add("周五");
strings.add("周六");
strings.add("周天");
接下来有两种方法
第一种:自己写一个类,继承自ValueFormatter,覆写getFormattedValue方法
public class Xxxxx extends ValueFormatter {
List<String> mStrings;
public Xxxxx (List<String> strings){
this.mStrings = strings;
}
@Override
public String getFormattedValue(float value) {
if (value<mStrings.size()){
return mStrings.get((int) value);
}else {
return "";
}
}
}
然后在主代码处
xAxis.setValueFormatter(new Xxxxx(strings));
这种方法在于灵活,在getFormattedValue方法中覆写可以覆写满足自己一些特别的需求
第二种:直接在主代码出使用MPAndroidChart提供的实现类
xAxis.setValueFormatter(new IndexAxisValueFormatter(strings));
简单方便。