Mpandroidchart: NegativeArraySizeException

Created on 26 Oct 2016  路  7Comments  路  Source: PhilJay/MPAndroidChart

Sample here:

        LineData chartData = mChart.getData();
        if (chartData == null) {
            chartData = new LineData();
            chartData.addDataSet(new LineDataSet(new ArrayList<Entry>(), ""));
            mChart.setData(chartData);
        }
        ILineDataSet dataSet = chartData.getDataSetByIndex(0);
        ArrayList<Entry> entries = new ArrayList<Entry>() {{
            add(new Entry(1477462516, 1));
            add(new Entry(1477462522, 5));
            add(new Entry(1477462527, 10));
        }};
        Collections.sort(entries, new EntryXComparator());
        for (Entry entry : entries) {
            dataSet.addEntry(entry);
        }

But getFormattedValue not called

        mChart.getXAxis().setValueFormatter(new IAxisValueFormatter() {
            @Override
            public String getFormattedValue(float value, AxisBase axis) {
                return MyDateFormatter.format(value);
            }

            @Override
            public int getDecimalDigits() {
                return 0;
            }
        });

and it throws this error:

java.lang.NegativeArraySizeException: -26
at com.github.mikephil.charting.utils.Transformer.generateTransformedValuesLine(Transformer.java:178)
at com.github.mikephil.charting.renderer.LineChartRenderer.drawValues(LineChartRenderer.java:545)
at com.github.mikephil.charting.charts.BarLineChartBase.onDraw(BarLineChartBase.java:251)
at android.view.View.draw(View.java:14506)
at android.view.View.getDisplayList(View.java:13403)

All 7 comments

maby you found solution for your problem?

same issue. and sorting the entries didn't fix it

same issue, someone find the solution?

I was getting the same error, then I checked out that my 1st entry point was some invalid entry. Removed that and now its working just fine.

I was getting the same error, then I checked out that my 1st entry point was some invalid entry. Removed that and now its working just fine.

Can i know the size of list you passed to dataset

In my case it turns out the reason was that in the previous version of the graph, we were creating a new entry with the following:

new Entry(value, index);

However, in the latest version of the library, you have to create an entry in reverse:

new Entry(index, value);

Was this page helpful?
0 / 5 - 0 ratings