ShinobiCharts: how to show X value and Y value when u click on the point of the chart

Now I am using the ShinobiCharts iOS chart diagram.

Can someone please give an example that will provide the function as the following image? enter image description here

I want to make a function that can show the value of X and the value of Y when u click on a point on the chart.

+5
source share
3 answers

You need to implement the SChartDelegate methods:

For instance,

- (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 method below to select a point

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

you need to set CrossHairEnabled for 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;
}
+3
source

To display the default crosshair, you need to set the following:

Enable crosshairs in a 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 hint

[chart.crosshair setDefaultTooltip];  
+2
source

All Articles