Mpandroidchart: PieChart disappears when adding 1 item

Created on 4 Apr 2016  路  6Comments  路  Source: PhilJay/MPAndroidChart

Hello Phil,

I just wanna say thanks for the library.. It's awesome.
I'm having a weird issue when adding just 1 item to the PieChart, when it finishes the animation the slice just becomes transparent with the label still visible as 100 %.

this is my implementation:

public class PieChartConstructor {


    private static PieChart mChart;

    public static PieChart construct(PieChart chart, ArrayList<Summary> items, SpannableString centerText) {
        mChart = chart;
        mChart.setUsePercentValues(true);
        mChart.setDescription("");
        mChart.setExtraOffsets(5, 10, 5, 5);
        mChart.setDragDecelerationFrictionCoef(0.95f);

        mChart.setDrawHoleEnabled(true);
        mChart.setHoleColor(Color.WHITE);


        mChart.setHoleRadius(75f);

        mChart.setDrawCenterText(true);
        mChart.setRotationAngle(0);

        mChart.setRotationEnabled(true);
        mChart.setHighlightPerTapEnabled(true);


        setData(items);
        return mChart;
    }

    private static void setData(ArrayList<Summary> items) {
        ArrayList<com.github.mikephil.charting.data.Entry> yVals1 = new ArrayList<com.github.mikephil.charting.data.Entry>();
        ArrayList<String> xVals = new ArrayList<String>();
        ArrayList<Integer> colors = new ArrayList<Integer>();
        for (int i = 0; i < items.size(); i++) {
            yVals1.add(new com.github.mikephil.charting.data.Entry(Float.parseFloat(items.get(i).total + ""), i));

            xVals.add("");
            colors.add(Color.parseColor(items.get(i).category.getColor()));
        }

        PieDataSet dataSet = new PieDataSet(yVals1, "Savings");
        dataSet.setSliceSpace(3f);
        dataSet.setSelectionShift(5f);
        dataSet.setColors(colors);


        PieData data = new PieData(xVals, dataSet);
        data.setValueFormatter(new PercentFormatter());
        data.setValueTextSize(11f);
        data.setValueTextColor(Color.WHITE);
        mChart.setData(data);


        mChart.highlightValues(null);
        mChart.getLegend().setEnabled(false);

        mChart.invalidate();
    }

}

Thanks

Most helpful comment

update to v2.2.4

All 6 comments

Post your build.gradle file please

compile 'com.github.PhilJay:MPAndroidChart:v2.2.3'

update to v2.2.4

done and worked.. thank you

It worked for me. Thanks o/

Thanks, works for me after updating to 2.2.4

Was this page helpful?
0 / 5 - 0 ratings

Related issues

OnlyInAmerica picture OnlyInAmerica  路  3Comments

SutharRohit picture SutharRohit  路  3Comments

AiTheAnswer picture AiTheAnswer  路  3Comments

JungYongWook picture JungYongWook  路  3Comments

vishvendu picture vishvendu  路  3Comments