How to get the barindex in toggel selection Method


#1

Hi

I created barchart with 3 series and each series having 3 bars.In the toggle selection delegate method iam able to get the series index but now i need to get the dataindex how to get that ???(means which bar i clicked barindex)Any help?


#2

Hi Anurag,

You can set your dataseries “selectionMode” property to SChartSelectionPoint and use the “-sChart:toggledSelectionForPoint:inSeries:atPixelCoordinate:” method with the below code inside it to find the SChartDataPoint’s index in its series:

int dataIndex = -1;
    // Loop through datapoints in series
    for(int i = 0;i <[[series dataSeries] dataPoints].count;i++){
        SChartDataPoint *dp = [[series dataSeries] dataPoints][i];
        // If datapoint values match up, store index
        if(dp.xValue == dataPoint.xValue && dp.yValue == dataPoint.yValue){
            dataIndex = i;
            i = [[series dataSeries] dataPoints].count;
        }
    }
    NSLog(@"%d", dataIndex);

Let me know how you get on.

Kind Regards,
Andrew Polkinghorn


#3

Thanks For the Late Reply .I already did.