I have a problem when I'm using "MPAndroidCharts" when I try to charge data into Bachar I use two ArrayList one ArrayList for Dates and one for data but it show's me a red line on BarData theData = new BarData(theDates,barDataSet);
My hole code for charts:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_statistics);
barChart = (BarChart)findViewById(R.id.bargraph);
BarInit();}
private void BarInit(){
ArrayList<BarEntry> barEntries = new ArrayList<>();
barEntries.add(new BarEntry(44f,0));
barEntries.add(new BarEntry(88f,1));
barEntries.add(new BarEntry(41f,2));
barEntries.add(new BarEntry(85f,3));
barEntries.add(new BarEntry(96f,4));
barEntries.add(new BarEntry(25f,5));
barEntries.add(new BarEntry(10f,6));
BarDataSet barDataSet = new BarDataSet(barEntries,"Dates");
ArrayList<String> theDates = new ArrayList<>();
theDates.add("Mars");
theDates.add("Avril");
theDates.add("Dec");
theDates.add("May");
theDates.add("OCt");
theDates.add("Nov");
theDates.add("Fir");
BarData theData = new BarData(theDates,barDataSet);//----Line of error
barChart.setData(theData);
barChart.setTouchEnabled(true);
barChart.setDragEnabled(true);
barChart.setScaleEnabled(true);
}
And when I cast "theDates" into IBarDataSet it display an other crash
using BarData theData = new BarData((IBarDataSet) theDates,barDataSet);
Process: com.example.transportor, PID: 13423 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.transportor/com.example.transportor.Statistics}: java.lang.ClassCastException: java.util.ArrayList cannot be cast to com.github.mikephil.charting.interfaces.datasets.IBarDataSet at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2308) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2368) at android.app.ActivityThread.access$800(ActivityThread.java:144) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1285) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:135) at android.app.ActivityThread.main(ActivityThread.java:5235) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:898) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:693) Caused by: java.lang.ClassCastException: java.util.ArrayList cannot be cast to com.github.mikephil.charting.interfaces.datasets.IBarDataSet at com.example.transportor.Statistics.BarInit(Statistics.java:239) at com.example.transportor.Statistics.onCreate(Statistics.java:73) at android.app.Activity.performCreate(Activity.java:6001) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2261) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2368) at android.app.ActivityThread.access$800(ActivityThread.java:144) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1285) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:135) at android.app.ActivityThread.main(ActivityThread.java:5235) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:898) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:693)