Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ShinobiCharts:How can show the X value and Y value when u click the point of the chart

I am now using ShinobiCharts iOS chart framework.

Can anyone please give me a example that provide the function as the following image? enter image description here

I want to do the function which can show the X value and Y value when u click the point of the chart.

like image 789
nullmicgo Avatar asked Feb 21 '13 04:02

nullmicgo


3 Answers

You have to implement the SChartDelegate methods:

For e.g.

- (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 
}

you can also use the below method for point selection

- (void)sChart:(ShinobiChart *)chart toggledSelectionForPoint:(SChartDataPoint *)dataPoint inSeries:(SChartSeries *)series atPixelCoordinate:(CGPoint)pixelPoint{
     //Your code goes here
}
like image 185
user1307850 Avatar answered Oct 22 '22 05:10

user1307850


you have to set CrossHairEnabled to YES something like this:

- (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;
}
like image 44
megara Avatar answered Oct 22 '22 04:10

megara


In order to display the default crosshair you need to set the following:

Enable crosshair on series

-(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;  
}

Use the default crosshair tooltip

[chart.crosshair setDefaultTooltip];  
like image 39
brandoneggar Avatar answered Oct 22 '22 05:10

brandoneggar