PhilJay / MPAndroidChart

A powerful 🚀 Android chart view / graph view library, supporting line- bar- pie- radar- bubble- and candlestick charts as well as scaling, panning and animations.
Other
37.53k stars 9.01k forks source link

IndexOutOfBoundsExeption #4381

Open Kwangjin-Lee opened 5 years ago

Kwangjin-Lee commented 5 years ago

I am using v3.0.3 and I found an exception.

java.lang.IndexOutOfBoundsException: Index: 0, Size: 0 at java.util.ArrayList.get(ArrayList.java:411) at com.github.mikephil.charting.data.DataSet.getEntryForIndex(Unknown Source) at com.github.mikephil.charting.utils.Transformer.generateTransformedValuesLine(Unknown Source) at com.github.mikephil.charting.renderer.LineChartRenderer.drawValues(Unknown Source) at com.github.mikephil.charting.charts.BarLineChartBase.onDraw(Unknown Source) at android.view.View.draw(View.java:17083) at android.view.View.updateDisplayListIfDirty(View.java:16065) at android.view.View.draw(View.java:16849) at android.view.ViewGroup.drawChild(ViewGroup.java:3768) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3554) at android.view.View.updateDisplayListIfDirty(View.java:16060) at android.view.View.draw(View.java:16849) at android.view.ViewGroup.drawChild(ViewGroup.java:3768) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3554) ......

tahakhozooie commented 5 years ago

I am using v3.0.3 and I found an exception.

java.lang.IndexOutOfBoundsException: Index: 0, Size: 0 at java.util.ArrayList.get(ArrayList.java:411) at com.github.mikephil.charting.data.DataSet.getEntryForIndex(Unknown Source) at com.github.mikephil.charting.utils.Transformer.generateTransformedValuesLine(Unknown Source) at com.github.mikephil.charting.renderer.LineChartRenderer.drawValues(Unknown Source) at com.github.mikephil.charting.charts.BarLineChartBase.onDraw(Unknown Source) at android.view.View.draw(View.java:17083) at android.view.View.updateDisplayListIfDirty(View.java:16065) at android.view.View.draw(View.java:16849) at android.view.ViewGroup.drawChild(ViewGroup.java:3768) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3554) at android.view.View.updateDisplayListIfDirty(View.java:16060) at android.view.View.draw(View.java:16849) at android.view.ViewGroup.drawChild(ViewGroup.java:3768) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3554) ......

If you're using IAxisValueFormatter, just add this code inside that:

   IAxisValueFormatter formatter = new IAxisValueFormatter() {
                @Override
                public String getFormattedValue(float value, AxisBase axis) {
                    if (((int) value) < YOURLISTDATA.size()) {
                        return YOURLISTDATA.get((int) value);
                    } else {
                        return "0";
                    }

                }
            };
Kwangjin-Lee commented 5 years ago

@tahagit I'm not using IAxisValueFormatter.