Programmatically showing chart crosshair + tooltip


Hi All,

I am trying to programatically show the crosshair and tooltip for the last datapoint in a chart after it loads. The below code is what I have so far. The crosshair shows in the right place, but the tooltip shows up way to the left and is too small to fit the text.

int num = [self.activeTrendsResult sChart:self.activeChart numberOfDataPointsForSeriesAtIndex:0];
    id<SChartData>data = [self.activeTrendsResult sChart:self.activeChart dataPointAtIndex:num-1 forSeriesAtIndex:0];
    double x = [[data sChartXValue] doubleValue];
    double y = [[data sChartYValue] doubleValue];
    SChartPoint p;
    p.x = x;
    p.y = y;
    [self.activeChart.crosshair moveToFloatingPosition:p onXAxis:self.activeChart.xAxis onYAxis:self.activeChart.yAxis];
    [self.activeChart.crosshair.tooltip setResolvedDataPoint:p fromSeries:self.activeChart.series[0] fromChart:self.activeChart];
    [self.activeChart.crosshair.tooltip setPosition:self.activeChart.crosshair.trackingPoint onCanvas:self.activeChart.canvas];

Any help would be much appreciated. 



One other related question. Can anyone tell me if there is a way to make the crosshair appear on single tap, rather than tap and hold? I’m assuming that if I can get the above code working, I can just call it from the chart delegate did select point, or is there a better way?



Your first question can be answered here:


To answer your second question, add the following category for SChartCanvasOverlay:

@interface SChartCanvasOverlay (CrosshairDuration)

- (void) changeLongPressDelay:(CFTimeInterval)time;


@implementation SChartCanvasOverlay (LongPress)

- (void) changeLongPressDelay:(CFTimeInterval)time


    [longPressGesture setMinimumPressDuration:time];



This exposes the long press gesture recognizer, and sets the minimum press duration. Now simply call changeLongPressDelay: on your canvas overlay and set the delay to 0. Bear in mind that once you do this you won’t be able to dismiss the crosshair with a tap, so if you want it to disappear you’ll have to remove it programatically:

[chart.crosshair removeCrosshair];

It is worth bearing in mind, that this is an internal implementation detail and it is not actually something we expose on our API, thus it might break in the future. Thought if it does, we’ll have probably added a way to do this onto our API.



Hello, I can not find the SChartCanvasOverlay in version 2.6.0. Is there a new solution for the tooltip to open with a single tap?


Add me to the list of folks who would like to see tooltips with a single tap.  I was able to find a way to make it work, but it was messy.


Added you :slight_smile:


I’m also interested in being able to show the crosshair with a single tap.



This should be fairly simple to accomplish if you’re using version 2.8.0 or later.

First of all we need to import a few header files that aren’t included in the ‘umbrella’ ShinobiChart.h header:

#import <ShinobiCharts/SChartCanvas.h>
#import <ShinobiCharts/SChartCanvasOverlay.h>

Then we create the UITapGestureRecognizer to call a method when a tap gesture is detected

UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(showCrosshair:)];

[chart.canvas.overlay addGestureRecognizer:tapGesture];

Finally, within that showCrosshair: method, we just need to convert get the user’s tap location relative to the chart and then show the crosshair.

- (void)showCrosshair:(UITapGestureRecognizer *)tapGestureRecognizer {
    CGPoint positionOfTap = [tapGestureRecognizer locationInView:chart];
    [chart.crosshair showAtPoint:positionOfTap inChart:chart];

I hope that helps  smiley lol




@sburnstone I like your approach. But then the crosshair does not follow when zooming in/out for some reason. Do you (or anyone) know how to solve this?


@yfujiki, sadly that’s a bug in ShinobiChart, I asked the same question here.[chartcrosshair-showatpointinchart]-has-strange-1st-time-behavior/