如何在PieChart中选择项目后重置选择

Dan*_*osa 5 android mpandroidchart

有谁知道,如何重置MPAndroid图表中的选定项目 - PieChart?我需要能够点击一个项目,例如"十万"次,但每次它都给我onNothingSelected()事件而不是onValueSelected()

我只需要调用onValueSelected()事件.

有人可以帮忙吗?

谢谢

Dan*_*ark 8

哇,我真的想要答案,最后,我解决了这个问题.

答案很简单.

chart.getOnTouchListener().setLastHighlighted(null);    
chart.highlightValues(null);
Run Code Online (Sandbox Code Playgroud)

在将highlightValues设置为null之前,您还需要初始化最后触摸的突出显示值!


Bre*_*ena 5

不知道你的问题解决了吗?但是,如果有人遇到同样的问题,这里有一个使用条形图的解决方案:

// global variables
protected static Entry entry;
protected static int index;
protected static Highlight highlight;

// function where the listener is defined
protected void manipulateChart(){

    final BarChart mChart = (BarChart) findViewById(R.id.your_chart);

    // listener
    mChart.setOnChartValueSelectedListener(new OnChartValueSelectedListener() {
        @Override
        public void onValueSelected(Entry e, int dataSetIndex, Highlight h) {
                // set global variables
                entry = e;
                index = dataSetIndex;
                highlight = h;

                mChart.highlightValues(null);
                // ... your code ...
            }
        }

        @Override
        public void onNothingSelected() {
            onValueSelected(entry, index, highlight);
        }
    });

} 
Run Code Online (Sandbox Code Playgroud)


Phi*_*oda 1

它位于文档中:https://github.com/PhilJay/MPAndroidChart/wiki/Interaction-with-the-Chart

在你的onValueSelected()方法中,调用

chart.highlightValues(null);
Run Code Online (Sandbox Code Playgroud)

撤消所有突出显示。