Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to reset selection after selecting item in PieChart

does anyone know, how to reset selected item in MPAndroid Charts - PieChart? I need to be able to click on one item for example "ten tousand" times, but every second time it gives me onNothingSelected() event not onValueSelected()

I need call only onValueSelected() event.

Can someone help?

Thank you

like image 284
Daniel Rosa Avatar asked Apr 15 '15 21:04

Daniel Rosa


2 Answers

Wow, I really wanted the answer and.. finally, I solved this problem.

The answer is very simple.

chart.getOnTouchListener().setLastHighlighted(null);    
chart.highlightValues(null);

Before set highlightValues as null, You need to also initialize the last touched highlighted value too!

like image 66
Daniel Park Avatar answered Nov 15 '22 06:11

Daniel Park


I don't know if you solved your problem. But, in case someone have the same problem, here is one solution using Bar Charts:

// 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);
        }
    });

} 
like image 44
Breno Macena Avatar answered Nov 15 '22 06:11

Breno Macena