The SChartCrosshair provides a small circle target with lines that extend to the axis. This is accompanied by a tooltip object - nominally a UIView. The default implementation for the tooltip is provided by
SChartCrosshairTooltip. For data points with multiple values at a single point, another implementation,
SChartCrosshairMultiValueTooltip, has also been provided.
The crosshair is enabled with a tap-and-hold gesture and will lock to the nearest series to pan through the values. On a line series the values will be interpolated between data points, on all other series types the crosshair will jump from data point to data point. Note that line series interpolation can be switched off by setting
In order for a crosshair to be displayed on a chart series, the series must have its
[SChartSeries crosshairEnabled] property set to
YES. This defaults to
NO, so you will need to set this property on the series in your chart.
More information about using SChartCrosshair can be found in the user guide, and in our tutorials ‘Customizing that Crosshair’ and ‘Data streaming, crosshairs and custom tooltips in ShinobiCharts’.
An alternative crosshair implementation,
SChartSeriesCrosshair, has also been provided.
Warning: Crosshairs are not currently supported on radial charts.
The crosshair holds a reference to the chart which contains it.
@property (nonatomic, weak) ShinobiChart *chart
If set to
YES the crosshair will move smoothly between points when tracking a line series.
@property (nonatomic) BOOL interpolatePoints
Otherwise the crosshair will jump from point to point as it tracks.
By default, this property is set to
Allows the user to customise the crosshair line by implementing the SChartCrosshairLineDrawer protocol.
@property (nonatomic, retain) id<SChartCrosshairLineDrawer> lineDrawer
By default, this will use implementation from SChartTargetLineDrawer.
This describes whether the crosshair is in floating mode or not.
@property (nonatomic) SChartCrosshairMode mode
The mode is defined with the following options:
Defines the behavior of the crosshair when it goes out of range.
@property (nonatomic) SChartCrosshairOutOfRangeBehavior outOfRangeBehavior
The crosshair has different behaviors for when it goes out of range. In this context, “out of range” refers to the case when a series goes off the screen - i.e. it is out of range on one axis, but not the other.
By default, the crosshair is set to
SChartCrosshairStyle object manages the look of the crosshair.
@property (nonatomic, retain) SChartCrosshairStyle *style
The default style for the crosshair is defined in the chart theme. If you wish to modify the look of the crosshair later on, you can set the properties on this object to achieve the desired look.
The tooltip which presents the current data values to the user.
@property (nonatomic, retain) SChartCrosshairTooltip *tooltip
By default, this will be an instance of
SChartCrosshairTooltip. You can also override this class to present the crosshair data in a custom way.
Configures the crosshair to track a particular data point on the chart.
@property (nonatomic, assign) SChartPoint trackingPoint
If this property isn’t set, the crosshair will lock to the nearest data point on the nearest series in the chart when it is drawn.
Configures the crosshair to track a particular series on the chart.
@property (nonatomic, retain, nullable) SChartMappedSeries *trackingSeries
If this property isn’t set, the crosshair will lock to the nearest series on the chart when it is drawn.
This method is called when the crosshair moves while inside the visible range of the chart.
This method is called when the crosshair moves out of the visible range of the chart.
The behaviour of the crosshair at this point is defined by its
Returns whether the crosshair should keep tracking. If this is the case, the crosshair should provide a series to track, using its
This method informs the crosshair that a gesture was performed which failed to select any series.
The default behavior in this case is to remove the crosshair.
Performs the drawing of the lines and the target circle element of the crosshair.
Override this function to provide custom lines or other drawn elements.
Initializes and returns a newly allocated crosshair object, which is associated with the specified chart.
- (id)initWithChart:(ShinobiChart *)parentChart
Moves the crosshair to the specified pixel coordinates.
The pixel coordinates to which to move the crosshair.
Moves the crosshair to the coordinates on the chart corresponding to the specified data point relative to the specified axes.
- (void)moveToFloatingPosition:(SChartPoint)point onXAxis:(SChartAxis *)xAxis onYAxis:(SChartAxis *)yAxis
The data point to which to move the crosshair.
The x axis with which the data point is associated. The x value of the data point will be mapped to this axis.
The y axis with which the data point is associated. The y value of the data point will be mapped to this axis.
This method is called when the crosshair changes position.
- (void)moveToPosition:(SChartPoint)coords andDisplayDataPoint:(SChartPoint)dataPoint fromSeries:(SChartMappedSeries *)series andSeriesDataPoint:(id<SChartData>)dataseriesPoint
The location on the chart where the crosshair should appear, in points.
The crosshair tooltip will display the value of this data point. This can either be an interpolated point, or the nearest actual point on the series, depending on the configuration of the crosshair.
The series on the chart which the crosshair is locked to.
This method is called by the chart when the crosshair should be dismissed. Override this method to control the display of the crosshair in subclasses.
YES if the crosshair should draw its tracking lines to the specified point, given the specified frame.
- (BOOL)shouldDrawCrosshairLinesForPoint:(CGPoint)point inFrame:(CGRect)frame
This defaults to a simple bounds check - whether the point is inside the frame.