PhilJay / MPAndroidChart

A powerful 🚀 Android chart view / graph view library, supporting line- bar- pie- radar- bubble- and candlestick charts as well as scaling, panning and animations.
Other
37.52k stars 9k forks source link

Disable highlights on pie chart/bar chart not working #3137

Open Vidxyz opened 7 years ago

Vidxyz commented 7 years ago

I'm trying to disable highlighting while clicking on a portion of the bar/pie chart but I want the onChartValueSelectedListener to fire at the same time. Basically, I don't want the bar/pie to change color/grow on value selected but I want to fire up a listener when this interaction occurs.

I've tried pieChart.setHighlightPerTapEnabled(false) but that doesn't fire the listener at all, how do I get around this?

Thanks in advance

vinod-hosamani commented 6 years ago

hi sir.... I am having one issue ,when I click on the barchart its getting highlight with the gray color,I want to remove that background color what i want to do please help me...........

Juxtlie commented 6 years ago

@vinod-hosamani To remove background color use setHighLightAlpha(0); For example

BarDataSet barDataSet = new BarDataSet(entries, ""); barDataSet.setHighLightAlpha(0);

Triyambak commented 5 years ago

barDataSet.setHighLightAlpha(0) is not working for me

Leftier commented 4 years ago

highlightPerTapEnabled must be true Then add the following code to onValueSelected:

    @Override
    public void onValueSelected(Entry entry, Highlight highlight) {
        chart.getOnTouchListener().setLastHighlighted(null);
        chart.highlightValues(null);
       // YOUR CODE
    }

Basically removing the highlights immediately after the click was detected

sahruday commented 4 years ago

With some custom modifications, working fine for me.

For Pie Chart:

piechart.onTouchListener = object : PieRadarChartTouchListener(pieChart){
     override fun onSingleTapUp(e: MotionEvent?): Boolean {
         super.onSingleTapUp(e)
         return super.onSingleTapUp(e)
         }
     }

For Bar Chart:

barChart.onTouchListener = object : BarLineChartTouchListener(barChart, barChart.viewPortHandler.matrixTouch, 3f){
    override fun onSingleTapUp(e: MotionEvent?): Boolean {
        super.onSingleTapUp(e)
        return super.onSingleTapUp(e)
        }
    }

onValuesSelected can be overridden to perform the required functionality

Ideology: onValuesSelected is been called only when highlighted but not on unhighlighting. So, in onSingleTapUp(e:MotionEvent?) we force it to highlight initially and then unhighlight as it programmed.

ajaymourya4 commented 4 years ago
dataSet.highLightColor = Color.TRANSPARENT
dataSet.highLightAlpha = 0

Adding the above two lines hides the highlight and doesn't affect the click listener

MaryReshma commented 4 years ago

Setting barDataSet.highLightAlpha = 0 removes the highlight tint in bars. But two taps would be needed to trigger OnChartValueSelectedListener the second time.

Adding @sahruday answer solves this issue perfectly

Ashok701 commented 3 years ago

I have removed highlight entries from the chart

Use below line

binding.chart1.getLegend().setEnabled(false);