【发布时间】:2016-04-09 10:49:39
【问题描述】:
JSONArray jsonArray = new JSONArray(result);
int length = jsonArray.length();
ArrayList<BarEntry> entries = new ArrayList<BarEntry>();
ArrayList<String> labels = new ArrayList<String>();
for (int i = 0; i < length; i++) {
entries.add(new BarEntry(Float.parseFloat(jsonArray.getJSONObject(i).getString("Potentials")), i));
labels.add(jsonArray.getJSONObject(i).getString("Name"));
}
BarChart chart = new BarChart(PotentialbySourceActivity.this);
BarDataSet dataset = new BarDataSet(entries, "# of Calls");
setContentView(chart);
BarData data = new BarData(labels, dataset);
chart.setData(data);
chart.setDragEnabled(true); // on by default
chart.setVisibleXRange(1,5);
chart.setHorizontalScrollBarEnabled(true);
chart.setDescription(""); // Hide the description
chart.getAxisLeft().setDrawLabels(true);
chart.getAxisRight().setDrawLabels(true);
chart.getXAxis().setDrawLabels(true);
Toast.makeText(PotentialbySourceActivity.this,"test",Toast.LENGTH_LONG).show();
chart.getLegend().setEnabled(true);
chart.setDescription("# of Industry");
dataset.setColors(ColorTemplate.COLORFUL_COLORS);
我正在使用 JSONArray 来填充我的 MPAndroid 条形图。但是条形图与它们的标签不一致。就像this 一样,任何人都可以帮助我将条形与相应的标签对齐吗?
【问题讨论】:
-
你试过这个 XAxis xAxis = mChart.getXAxis(); xAxis.setEnabled(true); nd INSIDE th // 将位置设置为 TOP ae 图表 xAxis.setPosition(XAxis.XAxisPosition.TOP_INSIDE);
-
欢迎来到 Stack Overflow,我已经编辑了您的代码块以减少缩进,使其更具可读性。有关格式化问题的更多信息,请参阅the editing help。
标签: java android mpandroidchart