ShinobiCharts选择一个专栏

时间:2012-11-17 12:37:00

标签: ios graph charts

我正在尝试使我的图表中的列可选,并在单击时显示所选列的更多详细信息。每列都由一个系列表示(您将在一秒钟内理解)。

这就是我构建每个系列的方式:

-(SChartSeries *)sChart:(ShinobiChart *)chart seriesAtIndex:(int)index {
    SChartColumnSeries *series = [SChartColumnSeries new];
    series.style.showAreaWithGradient = NO;
    series.stackIndex = [NSNumber numberWithInt:0];
    series.selectedStyle.showAreaWithGradient = NO;
    CHART_COLOR_TYPE dataType = [TestGraphDataManager getDataType:index];
    series.style.areaColor =    (dataType == ACCOUNT)?
                                    [UIColor colorWithRed:227.0f/255.0f green:179.0f/255.0f blue:0.0f/255.0f alpha:0.5f]:
                                    [UIColor colorWithRed:0.0f/255.0f green:172.0f/255.0f blue:235.0f/255.0f alpha:0.5f];

    series.selectedStyle.areaColor = [UIColor colorWithRed:129.0f/255.0f green:0.0f/255.0f blue:82.0f/255.0f alpha:0.5f];
    series.selectionMode = SChartSelectionSeries;

    series.style.lineColor = [UIColor clearColor];
    series.selectedStyle.lineColor = [UIColor clearColor];

    return series;
}

我目前遇到的问题是只有第一个系列是可选择的。另外我用不同系列表示每个条形图,这样我就可以用series.selectionMode = SChartSelectionSeries轻松切换颜色

最后我有这个委托事件,以便我可以加载额外的数据,但它也只为第一个系列调用

- (void)sChart:(ShinobiChart *)chart toggledSelectionForSeries:(SChartSeries *)series nearPoint:(SChartDataPoint *)dataPoint atPixelCoordinate:(CGPoint)pixelPoint{
    NSLog(@"click event called");
    //Display data
}

有谁知道为什么会这样?这一直让我疯狂。

先谢谢你的帮助。

修改 我找到了主要的问题,因为我做了series.stackIndex = [NSNumber numberWithInt:0];它使得所有的条形图具有相同的名称堆栈(名称的名称在我的观点中重复它不是问题),我这样做是为了让所有的条形都是与刻度线标记相同的距离,以便条形不是很尖。但我相信shinobi为这些价值观放置了隐形条,它们在另一个上面,只有第一个系列才可以选择,因为它超过了其他。如果我删除该行图形看起来很可怕但所有都是可点击的。 如何绕过这个或避免这个问题?

它应该如何显示(使用堆叠索引),但它会破坏点击事件: with stacking

没有堆叠索引所有条形都是可点击的,但它看起来不太好,而且越多,我只有4个条形条: without stacking

1 个答案:

答案 0 :(得分:1)

从Shinobi身边抢劫 - 感谢您的联系!

这可以通过使用子类来解决,并为列偏移返回零,如下所示:

@interface MyColumnSeries : SChartColumnSeries
@end

@implementation MyColumnSeries
- (double) offsetOfStackInChart:(ShinobiChart *)chart forDatapointIndex:(const int)pointIndex withPointSelector:(SEL)pointSelector
{
    return 0.0;
}
@end
相关问题