Android 记MPAndroid Chart 饼状图的扇形点击事件

 List xVals = new ArrayList<>();
        final List yVals = new ArrayList<>();
        for (int i = 0; i < list.size(); i++) {
            xVals.add(mTitle[i]);
            yVals.add(new Entry(list.get(i).getPm(), i));
        }
        pieChart.setOnChartValueSelectedListener(new OnChartValueSelectedListener() {
            @Override
            public void onValueSelected(Entry entry, int j, Highlight highlight) {
                if (entry == null) {
                    return;
                }
                //点击扇形区域各个模块事件
                if (yVals.get(0).getVal() == entry.getVal()) {
                    Toast.makeText(App.getContext(), mTitle[0], Toast.LENGTH_SHORT).show();
                } else if (yVals.get(1).getVal() == entry.getVal()) {
                   Toast.makeText(App.getContext(), mTitle[1], Toast.LENGTH_SHORT).show();
                } else if (yVals.get(2).getVal() == entry.getVal()) {
                   Toast.makeText(App.getContext(), mTitle[2], Toast.LENGTH_SHORT).show();
                } else if (yVals.get(3).getVal() == entry.getVal()) {
                    Toast.makeText(App.getContext(), mTitle[3], Toast.LENGTH_SHORT).show();
                } else if (yVals.get(4).getVal() == entry.getVal()) {
                   Toast.makeText(App.getContext(), mTitle[4], Toast.LENGTH_SHORT).show();
                }
            }

            @Override
            public void onNothingSelected() {
                //图表外部点击事件 也是(上一个方法为点击一次放大) 本方法为二次点击事件
            }
        });

 

你可能感兴趣的:(Android 记MPAndroid Chart 饼状图的扇形点击事件)