процент, как показать правую сторону в android для круговой диаграммы в android с помощью Mpchartandroid - PullRequest
0 голосов
/ 12 апреля 2020

Привет в приведенном ниже коде. Я реализовал круговую диаграмму со случайными процентами, хочу показать, какие проценты я получаю из круговой диаграммы, хочу показать в виде цветов, а также текста, а затем в процентах. Может ли кто-нибудь помочь мне решить эту проблему. Вместо 0 1 2 хотят показать проценты

 public final String[] parties = new String[] {"Completed","In Completed", "Scheduled"};
private void setData() {

        ArrayList<PieEntry> entries = new ArrayList<>();

        // NOTE: The order of the entries when being added to the entries array determines their position around the center of
        // the chart.
        for (int i = 0; i < 3 ; i++) {
            entries.add(new PieEntry((float) ((Math.random() * 10) + 10 / 5),
                    parties[i % parties.length].concat(":".concat(String.valueOf(i))),
                    getActivity().getResources().getDrawable(R.drawable.share)));

        }

        PieDataSet dataSet2 = new PieDataSet(entries, "");
        dataSet2.setDrawIcons(false);

        dataSet2.setSliceSpace(3f);
        dataSet2.setIconsOffset(new MPPointF(0, 40));
        dataSet2.setSelectionShift(5f);

        // add a lot of colors

//        ArrayList<Integer> colors = new ArrayList<>();
//
//        for (int c : ColorTemplate.VORDIPLOM_COLORS)
//            colors.add(c);
//
//        for (int c : ColorTemplate.JOYFUL_COLORS)
//            colors.add(c);
//
//        for (int c : ColorTemplate.COLORFUL_COLORS)
//            colors.add(c);
//
//        colors.add(ColorTemplate.getHoloBlue());

        int endColor3 = ContextCompat.getColor(getContext(), android.R.color.holo_green_dark);
        int endColor4 = ContextCompat.getColor(getContext(), android.R.color.holo_red_dark);
        int endColor5 = ContextCompat.getColor(getContext(), android.R.color.holo_orange_dark);

        List<Fill> gradientFills = new ArrayList<>();
        gradientFills.add(new Fill(endColor3, endColor3));
        gradientFills.add(new Fill(endColor4, endColor4));
        gradientFills.add(new Fill(endColor5, endColor5));

        dataSet2.setColors(endColor3,endColor5,endColor4);



        //dataSet.setSelectionShift(0f);

        PieData data2 = new PieData(dataSet2);
        data2.setValueFormatter(new PercentFormatter(chart2));
        data2.setValueTextSize(12f);
        data2.setValueTextColor(Color.WHITE);
        // data2.setValueTypeface(tfLight);
        chart2.setData(data2);


        // undo all highlights
        chart2.highlightValues(null);

        chart2.invalidate();
    }
...