ios - ShinobiCharts 选择列

标签 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

轻松切换其颜色

最后我有了这个委托(delegate)事件,这样我就可以加载额外的数据,但它也只在第一个系列中被调用

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

有人知道为什么会这样吗?这让我疯狂了一整天。

提前感谢您提供的任何帮助。

编辑: 我在做 series.stackIndex = [NSNumber numberWithInt:0]; 时发现了主要问题,它使所有具有相同名称的条堆叠起来(因为名称的重复在我看来不是问题 View ),我这样做是为了使所有条形图与刻度标记的距离相同,并且条形图不是很细。但我相信 shinobi 为这些值设置了无形的栏,并且它们位于另一个之上,因此只能选择第一个系列,因为它位于其他系列之上。如果我删除那条线,图形看起来很糟糕,但都可以点击。 关于如何绕过这个或避免这个问题的任何想法?

它看起来应该如何(使用堆叠索引)但它破坏了点击事件: with stacking

在没有堆叠索引的情况下,所有条形图都是可点击的,但它看起来不太好,而且我拥有的条形图越多,情况就越糟,这只使用了 4 个条形图: without stacking

最佳答案

Rob 来自 Shinobi - 感谢您与我们取得联系!

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

@interface MyColumnSeries : SChartColumnSeries
@end

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

关于ios - ShinobiCharts 选择列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13430622/

相关文章:

ios - 如何使用 Swift 中搜索栏下方的 cocoa pod 在 Google Place Autocomplete Picker View 中添加自定义当前位置按钮?

ios - 单独线程中的快速计时器

ios - UIImage 的 UIBezierPath

haskell - 将树转换为函数图库树的优雅方法?

mongodb - 如何将 MongoDB 图表嵌入到应用程序中

charts - 压缩/扩展JavaFX 2数据图表

ios - 将 MKCooperativeRegion 视为矩形是否会再次困扰我?

ios - 使用 faSTLane 部署后从 hockey 获取下载 url

algorithm - BFS 和 Dijkstra 算法在寻找最短路径时有什么区别?

algorithm - 给定一个无向图G = (V, E),判断G是否是完全图