3

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

Nikhil Manapure
  • 3,748
  • 2
  • 30
  • 55
Jess Murray
  • 1,273
  • 1
  • 10
  • 32

2 Answers2

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.

Nikhil Manapure
  • 3,748
  • 2
  • 30
  • 55
2

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.

Jess Murray
  • 1,273
  • 1
  • 10
  • 32