This is what worked for me. Attach an enum
value as the data
field of each entry, then analyze that value within the chartValueSelected
delegate method.
For instance, if you have two slices, create the enum
internal enum SliceType {
case pepperoni
case cheese
}
Then when constructing the PieChartDataSet
, construct your PieChartDataEntry
objects with their SliceType
as associated data:
let entry = PieChartDataEntry(value: pepperoniValue,
data: SliceType.pepperoni as AnyObject?)
Now make sure to set your view controller as the pie chart's delegate. Then in your chartValueSelected
delegate method, do something like the following:
func chartValueSelected(_ chartView: ChartViewBase, entry: ChartDataEntry, highlight: Highlight) {
// Extract the SliceType from the selected value
guard let sliceType = entry.data as? SliceType else {
return
}
switch sliceType {
case .pepperoni:
// Configure the view for pepperoni being selected
case .cheese:
// Configure the view for cheese being selected
}
}