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.65k stars 9.02k forks source link

Pie Chart section not shown if there is a "1" value #2472

Open bartonmartin opened 8 years ago

bartonmartin commented 8 years ago

I have a problem with Pie Chart

omfg

When I have Pie Chart with three values like on picture above, it never shows the smallest piece. I've tried different value formatters, I've tried changing colors, I've tried all different settings, but nothing helped me so far.

When I hardcode the same value for all the entries - for example "20" then it shows nice equal size, different color pieces. this_is_ok

pie setup method:

`setupPieChart(PieChart pieChart, List pieValues, String title) {

PieData data = generatePieData(pieValues); SpannableString centerText = generateSpannableCenterText(pieValues, title);

    pieChart.setCenterText(centerText);
    pieChart.setDrawHoleEnabled(true);
    pieChart.setHoleColor(Color.WHITE);
    pieChart.setHoleRadius(70f);
    pieChart.setTransparentCircleRadius(75f);
    pieChart.setDrawCenterText(true);

    pieChart.getLegend().setEnabled(false);
    pieChart.getDescription().setEnabled(false);

    pieChart.setTouchEnabled(false);
    pieChart.setRotationEnabled(false);
    pieChart.setHighlightPerTapEnabled(false);

    pieChart.highlightValues(null);
    pieChart.setData(data);
    pieChart.invalidate();
    pieChart.animateY(DELAY_MILLIS, Easing.EasingOption.EaseInOutQuad);

}`

and method for data generation is here:

`generatePieData(List values) { List pieEntryList = new ArrayList<>();

    for(int position = 0; position < values.size(); position++)
    {
        Long value = values.get(position);
        final PieEntry pieEntry = new PieEntry(value, position);
        if(value > 0)
        {
            pieEntryList.add(pieEntry);
        }
    }

.. List colors = new ArrayList<>(); for(int color : context.getResources().getIntArray(R.array.pie_chart_colors)) { colors.add(color); } ..

PieDataSet pieDataSet = new PieDataSet(pieEntryList, ""); pieDataSet.setDrawValues(true); pieDataSet.setColors(colors);

    final PieData pieData = new PieData(pieDataSet);
    return pieData;

}`

colors array: `

#00FF00
    <item>#FF0000</item>
    <item>#0000FF</item>
    <item>#000FF0</item>
    <item>#0FF000</item>
</integer-array>`

Also when I set all the values to "1" this happens. lol

nishantapatil commented 8 years ago

I am also facing same issue. Whenever value is 1, that slice becomes invisible. On selection it shows the slice properly. Is there a workaround for this? screenshot_20161118-195428 01 01

screenshot_20161118-195902 01

Thanks.

bartonmartin commented 8 years ago

@nishantapatil I've temporarily solved this with multiplying all values by a constant number. It's not ideal, but at least the graphs works.

nishantapatil commented 7 years ago

@bartonmartin But multiplying by constant value will affect the data. Which will cause inconsistency moving ahead. I have 3 level deep charts, there in one level down after selecting a slice in above screenshot. Any other hack?

nishantapatil commented 7 years ago

@bartonmartin Found a hack over here : #2329.

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)) { .... }

Basically now I am checking if ((value >= 1 && value <= Utils.FLOAT_EPSILON) { value = 1.0000002; }

This is still a hack but better than multiplying my constant number. Hope this helps.

nishantapatil commented 7 years ago

Fixed EPSILON. Take pull and rebuild.

nishantapatil commented 7 years ago

@danielgindi Please close this also.