本文介绍了如何在Mpcharts中为条形图添加X轴标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用的是旧版的MPCharts,并且运行良好,但是在3.0.2中,它似乎有点不同,它们的Wiki页面并没有太大帮助.
I was using an older version of MPCharts and in that it was working fine,but in 3.0.2,it seems to be a bit diferent,their wiki page isn't helping much.
这就是我所拥有的
ArrayList<BarEntry> entries = new ArrayList();
entries.add(new BarEntry(0,125f));
entries.add(new BarEntry(1,233f));
entries.add(new BarEntry(2,318f));
entries.add(new BarEntry(3,12f));
entries.add(new BarEntry(4,92f));
entries.add(new BarEntry(5,72f));
entries.add(new BarEntry(6,11f));
entries.add(new BarEntry(7,456f));
entries.add(new BarEntry(8,1567f));
entries.add(new BarEntry(9,367f));
entries.add(new BarEntry(10,753f));
entries.add(new BarEntry(11, 11f));
//entries.add(new BarEntry(233f, 12));
//entries.add(new BarEntry(555f, 6));
BarDataSet dataset = new BarDataSet(entries,"Rupees(₹)");
int colors1[] = {Color.rgb(178,34,34)};
dataset.setColors(colors1);
ArrayList<String> labels = new ArrayList();
labels.add("January");
labels.add("February");
labels.add("March");
labels.add("April");
labels.add("May");
labels.add("June");
labels.add("July");
labels.add("August");
labels.add("September");
labels.add("October");
labels.add("November");
labels.add("December");
BarData data = new BarData(dataset);
barChart.setData(data);
barChart.invalidate();
现在我不确定如何在X轴上添加Jan,Feb,March,任何帮助将不胜感激
Now i'm not sure how should i add Jan,Feb,March to X axis,any help would be appreciated
推荐答案
对于BarChart,您可以使用它在xAxis中设置标签
For the BarChart, u can use this to set the labels in xAxis
XAxis xAxis = barChart.getXAxis();
xAxis.setValueFormatter(new IndexAxisValueFormatter(labels));
有关更多信息,请查看其描述: IndexAxisValueFormatter
For more information, look on its description:IndexAxisValueFormatter
这篇关于如何在Mpcharts中为条形图添加X轴标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!