2.7.0 issue with SPieChart probably SChartInternalDataPoint issue ? name xValue missed


#1

Hello, on version 2.6.* this code worked fine:

- (id<SChartData>)sChart:(ShinobiChart *)chart dataPointAtIndex:(int)dataIndex forSeriesAtIndex:(int)seriesIndex {
        ParameterValue* pv = (ParameterValue*)[self.parameterValuesDataSource objectAtIndex: dataIndex];
        CGFloat val = pv.value;

        SChartRadialDataPoint *dp = [SChartRadialDataPoint new];
       
        // no negative values on pie charts !!!
        val = val >=0 ? val: 0.0;
       
        dp.value = [NSNumber numberWithFloat: val];
        dp.xValue = pv.parameter.title;
        dp.name = pv.parameter.title;
       
        return dp;
}

- (void)sChart:(ShinobiChart *)chart toggledSelectionForRadialPoint:(SChartRadialDataPoint *)dataPoint inSeries:(SChartRadialSeries *)series atPixelCoordinate:(CGPoint)pixelPoint {

    SChartPieSeries *pieSeries = (SChartPieSeries*)series;
   
    for (int i=0; i<pieSeries.dataSeries.dataPoints.count; i++) {
        SChartDataPoint *dp = [pieSeries.dataSeries.dataPoints objectAtIndex:i];

        if ([dp.xValue isEqualToString:dataPoint.name] == NO) {
            if (dataPoint.selected) {
                [pieSeries setSlice:i asSelected:NO];
            }

       }
    }
}

Basically, I was able to set SChartRadialDataPoint name and/or xValue to NSString and later get the NSString back.

In version 2.7.0-5

[pieSeries.dataSeries.dataPoints objectAtIndex:i];

returns object of class SChartInternalDataPoint which has no name property.

dp.xValue

returns NSNumber with index value instead of NSString which I set earlier. So my code crashes, as NSNumber has no isEqualToString: method :frowning:

Is it desired behaviour ? How can I fix the issue and get back my string values ?


#2

Hi deem0n,

Thanks for getting in touch!

Yes this is desired behaviour as SChartInternalDataPoint shouldn’t have been made public so now the “datapoints” array on a series “dataSeries” returns objects that conform to the SChartData protocol (id<SChartData>).

So replace “SChartDataPoint *dp = …” with “id<SChartData> dp = …” and replace “xValue” with “sChartXValue” to access the name property of an SChartRadialDataPoint.

Also, you don’t need to set the “xValue” on your datapoint you only need to set the “name” property.

Let me know if you have any more questions.

Kind Regards,
Andrew Polkinghorn


#3

Andrew, thank you!sChartXValue is what I need.