Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to skip values on particular indexes in Line Chart using MPAndroid Chart Library?

I am using MPAndroid Chart Library for plotting Line Chart and I am setting dynamic data on LineChart but sometimes I am getting data as value 0.0 for some indexes and I don't want show 0.0 values on any index. How can I skip indexes having 0.0 value.

ArrayList<Entry> entries = new ArrayList<>();
       entries.add(new Entry(23.00f, 0));
       entries.add(new Entry(40.00f, 1));
       entries.add(new Entry(00.00f, 2)); // want to skip this index 2(Mar)
       entries.add(new Entry(00.00f, 3)); // want to skip this index 3 (Apr)
       entries.add(new Entry(94.00f, 4));
       entries.add(new Entry(20.00f, 5));

Now i am getting like this enter image description here

But i would like to get some thing like this

enter image description here

Any Idea about this ?

Thanks

like image 829
Ghanshyam Nayma Avatar asked Feb 25 '16 09:02

Ghanshyam Nayma


3 Answers

Finally after a lot of Internet search , i found solution. I tried many solutions but in my case and best fit with question is as well.

Get the axis suppose we are planning to hide useless sequence value from the xAxix

xAxis.setLabelCount(originalValueArray.size, true)

where originalValueArray is the array of original data source.

Above solution will only draw required label and it will remove unnecessary sequence data.

like image 189
IshRoid Avatar answered Sep 22 '22 11:09

IshRoid


What about adding multiple dataset, one for each contiguous part of your graph ?

like image 38
PhilippeAuriach Avatar answered Sep 18 '22 11:09

PhilippeAuriach


You can try Override drawData method from LineChartRender and do this:

int index = lineData.getDataSets().size();
for (ILineDataSet set : lineData.getDataSets()) {            
                if (set.getEntryForIndex(index).getY() != 0) {
                    if (set.isVisible()) {
                        drawDataSet(c, set);
                    }
                }

        c.drawBitmap(mDrawBitmap.get(), 0, 0, mRenderPaint);
    }
}
like image 31
Pau Molina Avatar answered Sep 18 '22 11:09

Pau Molina