Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting an IllegalArgumentException while adding line data

When more than some datasets (around 6 or more) to a line graph, we are getting an exception.
This is the detail:

 java.lang.IllegalArgumentException: One or more of the DataSet Entry arrays are longer than the x-values array of this ChartData object.
 at com.github.mikephil.charting.data.ChartData.isLegal(ChartData.java:173)
 at com.github.mikephil.charting.data.ChartData.init(ChartData.java:130)
 at com.github.mikephil.charting.data.ChartData.<init>(ChartData.java:96)
 at com.github.mikephil.charting.data.BarLineScatterCandleData.<init>(BarLineScatterCandleData.java:27)
 at com.github.mikephil.charting.data.LineData.<init>(LineData.java:27)

I am not able to understand the reason why.
I am using MPAndroidChart to plot the graph.
When more data sets are entered, we are getting that exception.

like image 390
Vishwa Avatar asked Mar 15 '23 05:03

Vishwa


1 Answers

The error is exactly as explained. Heres it visually in case its a language barrier

............................---------------------------
Chart .................|. 1 ... 2 ... 3 ... 4 ... 5 .|
Data Set 1 .........|. a ... b ... c ... d ... e .|
Data Set 2 .........|. a ... b ... c ... d ... e .|
Data Set 3 .........|. a ... b ... c ... d ... e .|
Data Set 4 .........|. a ... b ... c ... d ... e .|
Data Set 5 .........|. a ... b ... c ... d ... e .|
Data Set 6 .........|. a ... b ... c ... d ... e .|
Data Set 7 .........|. a ... b ... c ... d ... e .|... f ... g
............................---------------------------

As you can see the last data set has too many items to fit into the chart so the app does not know how to handle it and throws an error

like image 84
Nick Cardoso Avatar answered Mar 24 '23 19:03

Nick Cardoso