toggleSelection is not working in SChartDonutSeries


#1

Hi,

I try to implement Donut chart so that only one point is selected.
I set togglePointSelection to false, but it doesn’t work. Did I miss something?

I use it like this

` override func getSeriesForChart(color: UIColor, negativeColor: UIColor) -> SChartSeries {

    let pieSeries = SChartDonutSeries()
    pieSeries.togglePointSelection = true
    pieSeries.toggleSelection = true 
    return pieSeries
}`

#2

Hi Marko,

Thanks for getting in touch!

The “togglePointSelection” is the correct property to use, however, it does not work for our radial series (donut & pie).

I’ve added a task to our backlog to investigate this further.

In the meantime, you can implement the desired behaviour using the following implementation of the “sChart:toggledSelectionForRadialPoint:atPixelCoordinate:” SChartDelegate method:

-(void)sChart:(ShinobiChart *)chart toggledSelectionForRadialPoint:(SChartRadialDataPoint *)dataPoint inSeries:(SChartRadialSeries *)series atPixelCoordinate:(CGPoint)pixelPoint {
    
    if(_selectedDP){
        SChartDonutSeries *donut = (SChartDonutSeries *)series;
        NSUInteger index = [donut.dataSeries.dataPoints indexOfObject:_selectedDP];
        [donut setSlice:index asSelected:NO];
    }
    if([_selectedDP isEqual:dataPoint]){
        _selectedDP = nil;
    } else {
        _selectedDP = dataPoint;
    }
}

Where _selectedDP is an instance variable that stores the selected data point.

Let me know if you have any questions.

Kind regards,
Andrew Polkinghorn.


#3

Androw,

thank you very much.

I am posting the swift version of your code, if any one else will look at this :

func sChart(_ chart: ShinobiChart, toggledSelectionFor dataPoint: SChartRadialDataPoint, in series: SChartRadialSeries, at pixelPoint: CGPoint) {
    
    
    if selectedDataPoint != nil {
        
        let donut = series as! SChartDonutSeries
        
        if donut.selectedDataPoints.contains(selectedDataPoint!) {
            
            donut.setSlice(selectedDataPoint!.index, asSelected: false)
        }
    }
    if selectedDataPoint == dataPoint {
        selectedDataPoint = nil
    } else {
        selectedDataPoint = dataPoint
    }
}