4

I am looking for a way of forcing the slice of the pie chart to become unselected. It automatically deselects when you click out of the pie chart however I was wondering if there was a way to deselect it within a button action?

I have various buttons which displays filtered versions of the same data and, if a slice is selected when you click a button it remains selected.

Any help would be great.

Thanks

2 Answers 2

7
 pieChart.highlightValue(nil)

This worked for me. I am on Charts (3.0.2), Swift 3, XCode 8.3.3.

Hope this helps someone.

1
  • Lot easier than the other answer! Commented Mar 28, 2019 at 12:34
3

Within the function chartValueSelected which is called when a slice has been selected/highlighted, I set a global variable containing the DataSetIndex:

var dataSetIndexToDeselect : Int = 0
func chartValueSelected(chartView: ChartViewBase, entry: ChartDataEntry, dataSetIndex: Int, highlight: ChartHighlight) {
    dataSetIndexToDeselect = dataSetIndex  
}

On the button click, i unhighlight the slice by adding the following line the the IBAction:

@IBAction func buttonClick(sender: AnyObject) {
    pieChartView.highlightValue(xIndex: -1, dataSetIndex: dataSetIndexToDeselect, callDelegate: false)
}

The '-1' on the xIndex causes the 'dataSetIndexToDeselect' value to no longer be selected.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.