如何在MPA图表中使用setOnChartValueSelectedListener作为饼图

时间:2019-02-28 15:48:41

标签: android mpandroidchart

我要移动活动,在该活动中,它会根据上一个活动中选择的图表值显示其他图表数据。但是我对如何实现它感到困惑。有人知道如何实施上述案件吗?

这是我的代码:

Call<PadmResponse> call = RetrofitClient.getmInstance().getApi().showPadm();
    call.enqueue(new Callback<PadmResponse>() {
        @Override
        public void onResponse(@NonNull Call<PadmResponse> call, @NonNull Response<PadmResponse> response) {
            assert response.body() != null;
            padmList = response.body().getPadmList();

            pieChart.setUsePercentValues(false);
            pieChart.getDescription().setEnabled(false);
            pieChart.setExtraOffsets(5, 10, 5, 5);

            pieChart.setDragDecelerationFrictionCoef(0.95f);
            pieChart.setDrawHoleEnabled(true);
            pieChart.setHoleRadius(30);
            pieChart.setHoleColor(Color.WHITE);
            pieChart.setTransparentCircleRadius(40f);

            ArrayList<PieEntry> yvalues = new ArrayList<>();
            for (int i = 0; i < padmList.size(); i++) {
                Padm padm = padmList.get(i);
                String kabupaten = padm.getNm_kabupaten();
                String total = padm.getTotal_mahasiswa();
                yvalues.add(new PieEntry(Integer.parseInt(total), kabupaten));
            }

            Description description = new Description();
            description.setText("Total Data Persebaran Mahasiswa FKTI UNMUL PRODI TI");
            description.setTextSize(10);
            pieChart.setDescription(description);

            pieChart.animateY(1000, Easing.EasingOption.EaseInOutCubic);

            PieDataSet pieDataSet = new PieDataSet(yvalues, "Kabupaten/Kota");
            pieDataSet.setSliceSpace(2f);
            pieDataSet.setSelectionShift(5f);

            final int[] MY_COLORS = {Color.rgb(192,0,0), Color.rgb(255,0,0), Color.rgb(255,192,0),
                    Color.rgb(127,127,127), Color.rgb(146,208,80),
                    Color.rgb(0,176,80), Color.rgb(79,129,189), Color.rgb(255,0,149),
                    Color.rgb(230,0,255), Color.rgb(18,0,255), Color.rgb(245,139,9)};
            ArrayList<Integer> colors = new ArrayList<>();

            for(int c: MY_COLORS) colors.add(c);
            pieDataSet.setColors(colors);
            pieDataSet.setValueFormatter(new DecimalRemover(new DecimalFormat("###,###,###")));

            PieData data = new PieData(pieDataSet);
            data.setValueTextSize(10f);
            data.setValueTextColor(Color.BLACK);

            pieChart.setData(data);

            pieChart.setOnChartValueSelectedListener(new OnChartValueSelectedListener() {
                @Override
                public void onValueSelected(Entry e, Highlight h) {
                    //IDK, what's next
                }

                @Override
                public void onNothingSelected() {

                }
            });

        }

        @Override
        public void onFailure(Call<PadmResponse> call, Throwable t) {
            Toast.makeText(GrafikPadmActivity.this, "Server Gagal Merespon", Toast.LENGTH_SHORT).show();
        }
    });

我试图找到自己的方式,但是仍然无法基于先前选择的图形数据显示图形

0 个答案:

没有答案
相关问题