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

PieChart % bug #4556

Open 775341604 opened 5 years ago

775341604 commented 5 years ago

piec2 = findViewById(R.id.piechart2); piec2.setExtraOffsets(20.f, 0.f, 20.f, 0.f); piec2.setDrawEntryLabels(true); piec2.setUsePercentValues(true); piec2.setCenterText("剩余时间项目比例");

    List<PieEntry> strings = new ArrayList<>();
    strings.add(new PieEntry(2, "已超时"));
    strings.add(new PieEntry(2, "少于7天"));
    strings.add(new PieEntry(3, "7天以上"));
    strings.add(new PieEntry(4, "15天以上"));
    strings.add(new PieEntry(3, "30天以上"));
    strings.add(new PieEntry(5, "60天以上"));
    strings.add(new PieEntry(3, "90天以上"));
    ArrayList<Integer> colors = new ArrayList<Integer>();
    colors.add(Color.parseColor("#ffa8a8"));
    colors.add(Color.parseColor("#ffc078"));
    colors.add(Color.parseColor("#ffe066"));
    colors.add(Color.parseColor("#8ce99a"));
    colors.add(Color.parseColor("#66d9e8"));
    colors.add(Color.parseColor("#74c0fc"));
    colors.add(Color.parseColor("#e599f7"));

    PieDataSet dataSet = new PieDataSet(strings, "");
    dataSet.setDrawValues(true);
    dataSet.setColors(colors);
    dataSet.setHighlightEnabled(true);
    dataSet.setValueLinePart1OffsetPercentage(80.f);
    dataSet.setValueLinePart1Length(0.4f);
    dataSet.setValueLinePart2Length(0.4f);
    dataSet.setYValuePosition(PieDataSet.ValuePosition.OUTSIDE_SLICE);
    dataSet.setUsingSliceColorAsValueLineColor(true);

    PieData pieData = new PieData(dataSet);
    pieData.setDrawValues(true);
    pieData.setValueFormatter(new PercentFormatter());
    pieData.setValueTextSize(12f);
    pieData.setValueTextColors(colors);
    piec2.setData(pieData);

    Legend mlegend = piec2.getLegend();
    mlegend.setWordWrapEnabled(true);
    mlegend.setTextSize(12f);
    mlegend.setEnabled(false);

    Description description = new Description();
    description.setText("");
    piec2.setDescription(description);

    piec2.invalidate();

why % is dismiss?

myring100 commented 4 years ago

https://github.com/PhilJay/MPAndroidChart/issues/4519#issuecomment-544065212

Check it out.

duytient31 commented 3 years ago
    data.setValueFormatter(new PercentFormatterCustomer(binding.pieChart));
kairos1729 commented 3 years ago

Also: https://github.com/PhilJay/MPAndroidChart/issues/4519#issuecomment-850759475