How to select a Column series Bar in code

2019-09-18 15:42发布

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.

1条回答
Lonely孤独者°
2楼-- · 2019-09-18 16:00

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.

查看更多
登录 后发表回答