0

我有两个系列,如何同时选择两个系列?基本上,我的图表有 2 个 y 值共享相同的 x 值,我将它们表示为两个系列。我想显示为给定 X 值选择的两个点。

您好,谢谢您的回复。
我正在这样做

- (void)sChart:(ShinobiChart *)chart toggledSelectionForPoint:(SChartDataPoint *)dataPoint inSeries:(SChartSeries *)series atPixelCoordinate:(CGPoint)pixelPoint

    SChartDataPoint* point1Series1 = [chart.datasource sChart:chart dataPointAtIndex:dataPoint.index forSeriesAtIndex:0];
    point1Series1.selected = YES;

    SChartDataPoint* point1Series2 = [chart.datasource sChart:chart dataPointAtIndex:dataPoint.index forSeriesAtIndex:1];
    point1Series2.selected = YES;

当我在这行代码之后打印两个点的选定状态时,它们返回 1(selected) 但它们似乎没有在图表上显示为选中状态,只有我在设备上的图表上选择的那个似乎显示为选中状态在那之后我打电话给redrawChart。任何帮助,将不胜感激

4

2 回答 2

2

我认为很可能(我猜是因为我看不到您的代码)您的图表数据源没有返回对作为图表一部分的数据点的引用,而是每次都生成一个新的数据点对象你要求一个。

为了解决这个问题,您可以通过对象的dataSeries属性从图表本身请求数据点SChartSeries

以下委托方法应执行您需要的选择。

- (void)sChart:(ShinobiChart *)chart toggledSelectionForPoint:(SChartDataPoint *)dataPoint inSeries:(SChartSeries *)series atPixelCoordinate:(CGPoint)pixelPoint
{
    // Selection details
    NSInteger dataPointIndex = dataPoint.index;
    BOOL selected = dataPoint.selected;

    for (SChartSeries *chartSeries in chart.series) {
        // If only one data point in the series can be selected at once, then deselect the rest
        if(!series.togglePointSelection && selected) {
            for(SChartDataPoint *dp in chartSeries.dataSeries.dataPoints) {
                dp.selected = NO;
            }
        }
        // Find the data point and perform the selection
        SChartDataPoint *dp = chartSeries.dataSeries.dataPoints[dataPointIndex];
        dp.selected = selected;
    }
}

希望有帮助。

于 2013-12-14T22:15:06.450 回答
0

您应该能够在数据点上设置 .selected 并自定义 series.style.selectedPointStyle 属性以显示您希望的点:)

于 2013-12-13T17:20:53.167 回答