ShinobiCharts:当你点击图表的点时,如何显示X值和Y值

时间:2013-02-21 04:32:55

标签: ios charts shinobi

我现在正在使用ShinobiCharts iOS图表框架。

任何人都可以给我一个例子,提供如下图所示的功能吗? enter image description here

当你点击图表的点时,我想做一个可以显示X值和Y值的函数。

3 个答案:

答案 0 :(得分:4)

您必须实现SChartDelegate方法:

例如

- (void)sChart:(ShinobiChart *)chart toggledSelectionForSeries:(SChartSeries *)series nearPoint:(SChartDataPoint *)dataPoint atPixelCoordinate:(CGPoint)pixelPoint{
NSLog(@"x value:%@",dataPoint.xValue);
NSLog(@"y value:%@",dataPoint.yValue);
//here you can create an label to show the x/y values or even can add an annotation 
}

您也可以使用以下方法进行点选择

- (void)sChart:(ShinobiChart *)chart toggledSelectionForPoint:(SChartDataPoint *)dataPoint inSeries:(SChartSeries *)series atPixelCoordinate:(CGPoint)pixelPoint{
     //Your code goes here
}

答案 1 :(得分:3)

你必须将CrossHairEnabled设置为YES,如下所示:

- (SChartSeries*)barSeriesForKey:(NSString*)key {

SChartBarSeries *series = [SChartBarSeries new];

series.stackIndex = [NSNumber numberWithInt:1];
series.crosshairEnabled = YES; // this is what you want
series.title = [self titleForKey:key];

if ([key isEqualToString:land]) {

    series.style = [self.theme barSeriesStyleForSeriesAtIndex:3 selected:NO];
}

return series;
}

答案 2 :(得分:2)

要显示默认十字准线,您需要设置以下内容:

在系列

上启用十字准线
-(SChartSeries *)sChart:(ShinobiChart *)chart seriesAtIndex:(int)index {  
    SChartLineSeries *lineSeries = [[SChartLineSeries alloc] init];  
    lineSeries.style.lineColor = [UIColor darkGrayColor];  
    lineSeries.crosshairEnabled = YES;  
    lineSeries.selectionMode = SChartSelectionPoint;  
    return lineSeries;  
}

使用默认的十字准线工具提示

[chart.crosshair setDefaultTooltip];