6

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

4
  • you can skip adding 0.0 to your graph
    – Sree
    Commented Feb 25, 2016 at 10:02
  • @Sree exactly what i have to do for skip this values ?
    – GS Nayma
    Commented Feb 25, 2016 at 10:07
  • Did you find any solution? if yes, plz share. I am also stuck in same scenario. Commented Feb 25, 2018 at 18:16
  • @RahulParihar Yes some how it was done but need to find that code and will post it here shortly
    – GS Nayma
    Commented Feb 26, 2018 at 5:57

4 Answers 4

2

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.

1

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

1

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);
    }
}
0

Your code should be looking as:

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));

The lib will draw it automatically as on screenshot 2.

2
  • It does not work man. I tried this before posting my question here.
    – GS Nayma
    Commented Nov 24, 2016 at 4:50
  • I have similar task and not adding data works for me. The other option is to have the Array list of colors for the points and make the the 00,00f entries color transparent. And change it after that to the new value, calculated to
    – Evgeny
    Commented Nov 24, 2016 at 6:34

Not the answer you're looking for? Browse other questions tagged or ask your own question.