enter image description here我在我的项目中使用MP条形图。我复制粘贴一个教程中的代码。该教程中的代码工作得很好,但在我的项目中出现错误。MP条形图android错误
BarChart barChart = (BarChart) findViewById(R.id.barchart);
ArrayList<BarEntry> entries = new ArrayList<>();
entries.add(new BarEntry(8f, 0));
entries.add(new BarEntry(2f, 1));
entries.add(new BarEntry(5f, 2));
entries.add(new BarEntry(20f, 3));
entries.add(new BarEntry(15f, 4));
entries.add(new BarEntry(19f, 5));
BarDataSet bardataset = new BarDataSet(entries, "Cells");
ArrayList<String> labels = new ArrayList<String>();
labels.add("2016");
labels.add("2015");
labels.add("2014");
labels.add("2013");
labels.add("2012");
labels.add("2011");
//error on this line because of string arraylist
//BarData data = new BarData(labels, bardataset);
barChart.setData(data); // set the data and list of lables into chart
barChart.setDescription("Set Bar Chart Description"); // set the description
bardataset.setColors(ColorTemplate.COLORFUL_COLORS);
barChart.animateY(5000);
// XML文件
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.github.mikephil.charting.charts.BarChart
android:id="@+id/barchart"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<!--com.jjoe64.graphview.GraphView
android:id="@+id/graph"
android:layout_width="match_parent"
android:layout_height="200dip" /-->
</LinearLayout>
请分享你的错误记录。 –
错误不在运行时,我无法运行,红色线下面 –
设置barChart.setData(bardataset);而不是barChart.setData(data); –