0

I have a bar graph chart working and I can select bars by tapping them.

In -sChart:seriesAtIndex: of my ShinobiChart datasource I have implemented:

SChartColumnSeries *series = [[SChartColumnSeries alloc] init];
series.detectTapsOutsideBar = YES;
series.selectionMode = SChartSelectionPoint;

Which is working well. What I want to do now is to be able to select a specific bar based on the index of the data behind it. How do you do this? I have looked on the chart, the series but cannot find any method to select a column.

Also for extra points :) I need to ensure at least one column is always selected.

UPDATE:

I tried adding the following code:

for (int index = 0; index < self.chartView.series[0].dataSeries.dataPoints.count; index++)
{
    SChartDataPoint *point = (SChartDataPoint *)self.chartView.series[0].dataSeries.dataPoints[index];
    if (lapIndex == index)
    {
        point.selected = YES;
    }
    else
    {
        point.selected = NO;
    }
}

Seemed to have no effect at all. I also tried re drawing the chart.

In the end I removed that code and called -reloadData and -redrawChart on the chart and then set selected in the datasource. This is working.

Ants
  • 1,338
  • 16
  • 27

1 Answers1

1

DISCLAIMER I am a developer at ShinobiControls.

We have recently changed our data point selection API which shall be coming up in our next release to make this a bit clearer.

Currently, you have to loop through your series' data points via the "dataSeries.dataPoints" array. Then cast the point you pulled off the array from type id to SChartDataPoint and set the selected property on that point.

Or if you want to select a data point when your chart initially draws, you can just set the selected property of the SChartDataPoint object you return in the SChartDatasource method "dataPointAtIndex:".

To make sure only one point is selected at a time you can set the "togglePointSelection" BOOL property to NO. Setting this property to YES means you can select more than one point at a time.

MrAPolk
  • 116
  • 2
  • Thank you for this. I am setting the first point to selected in -sChart:dataPointAtIndex:forSeriesAtIndex: and I have implemented -sChart:toggledSelectionForPoint:inSeries:atPixelCoordinate: in my delegate and iterated over all the dataPoints, if there are none selected then I extract the current dataPoint from the dataPoints array and re set the selection property. This has given me the functionality that I need, i.e. always at least one bar is selected. – Ants Jun 30 '16 at 21:36
  • Interestingly just setting the selected flag on the dataPoint returned in the delegate method had no effect. – Ants Jun 30 '16 at 21:37