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)の代わりに。 –