Mpandroidchart: PieChart low value - background

Created on 4 Oct 2016  路  10Comments  路  Source: PhilJay/MPAndroidChart

Hello,
i have problem with you libraries. When have many value big and low it don't good display on the graph:

2016-10-03_14 50 49

Most helpful comment

@PhilJay The problem seems to be related to drawing values that are very small when compared to the total (i.e. an angle of the pie that measures to less than one degree). An in particular, it seems to be caused by this condition in PieRenderer.drawDataSet():

    if (sweepAngleOuter % 360f <= Utils.FLOAT_EPSILON) {
        // Android is doing "mod 360"
        mPathBuffer.addCircle(center.x, center.y, radius, Path.Direction.CW);

By changing this code so that it never goes inside this branch (i.e. if (false) { ...) then the pie is drawn correctly. Problem is, I didn't really understand the purpose of that check, so I'm not sure about the consequences of changing it. :(

How to reproduce

In the sample's PieChartActivity, alter the setData() method by commenting out the part that generates the entry values and replacing it by this code:

    /*
    for (int i = 0; i < count ; i++) {
        entries.add(new PieEntry((float) ((Math.random() * mult) + mult / 5), mParties[i % mParties.length]));
    }
    */

    entries.add(new PieEntry(197, "A"));
    entries.add(new PieEntry(1344, "B"));
    entries.add(new PieEntry(314, "C"));
    entries.add(new PieEntry(3, "D"));

You will see that the whole pie is covered by the color of the last entry (the smallest one). Some other artifacts may be present too, depending on the order of the entries.

Tested on 3.0.0 release.

All 10 comments

Same issue for me

Hello could we help me ? Black background in pie chart #151 not working Me :(

@PhilJay The problem seems to be related to drawing values that are very small when compared to the total (i.e. an angle of the pie that measures to less than one degree). An in particular, it seems to be caused by this condition in PieRenderer.drawDataSet():

    if (sweepAngleOuter % 360f <= Utils.FLOAT_EPSILON) {
        // Android is doing "mod 360"
        mPathBuffer.addCircle(center.x, center.y, radius, Path.Direction.CW);

By changing this code so that it never goes inside this branch (i.e. if (false) { ...) then the pie is drawn correctly. Problem is, I didn't really understand the purpose of that check, so I'm not sure about the consequences of changing it. :(

How to reproduce

In the sample's PieChartActivity, alter the setData() method by commenting out the part that generates the entry values and replacing it by this code:

    /*
    for (int i = 0; i < count ; i++) {
        entries.add(new PieEntry((float) ((Math.random() * mult) + mult / 5), mParties[i % mParties.length]));
    }
    */

    entries.add(new PieEntry(197, "A"));
    entries.add(new PieEntry(1344, "B"));
    entries.add(new PieEntry(314, "C"));
    entries.add(new PieEntry(3, "D"));

You will see that the whole pie is covered by the color of the last entry (the smallest one). Some other artifacts may be present too, depending on the order of the entries.

Tested on 3.0.0 release.

@matiash I faced the following issues-

  1. If the Value is less than 1, that sector is not displayed.
  2. When Multiple entries, the color of the last sector is displayed on the whole pie for a brief flash before the other sectors get loaded.

The issue for problem 1 is this part in the PieRenderer-
// draw only if the value is greater than zero
if ((Math.abs(e.getY()) > Utils.FLOAT_EPSILON)) {
....
}
The value of Utils.FLOAT_EPSILON is 1.0000001 so the condition is always true. Values less than 1 thus arent drawn.

The issue for problem 2 is as @matiash suggested, since the condition :

sweepAngleOuter % 360f <= Utils.FLOAT_EPSILON

is true

@bharatnadkarni Indeed. I just wanted to point out that this happens for small angles even when the values themselves are greater than 1.

Same problem here, when the fix for this will come? @PhilJay

Same problem.

Happening here too on first attempt to integrate the lib.

Basically happens when the value is somewhere around 1.
If this value of 1 is third in the ArrayList of size 5, the rest of the entries or Pie Chart blocks, adding up later do not show a highlighted colour unless clicked upon.

It's 2018 and I'm getting this. Still no Updates?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

rohitkumarbhagat picture rohitkumarbhagat  路  3Comments

OnlyInAmerica picture OnlyInAmerica  路  3Comments

AndroidJiang picture AndroidJiang  路  3Comments

andreyfel picture andreyfel  路  3Comments

JungYongWook picture JungYongWook  路  3Comments