iOS & macOS Charting Documentation - SciChart iOS & macOS Charts SDK v4.x

The SCIAxisMarkerAnnotation

The SCIAxisMarkerAnnotation type allows to place markers with custom text onto X or Y axes. They show the axis value at their location by default:

Axis Marker Annotation

NOTE: Examples of the Annotations usage can be found in the SciChart iOS Examples Suite as well as on GitHub:

The SCIAxisMarkerAnnotation can be configured using the properties listed in the table below:

Feature Description
SCIAxisMarkerAnnotation.formattedValue Allows to specify the text that will appear on the marker.
SCIAxisMarkerAnnotation.formattedLabelValueProvider Allows to override the default formatted value, which comes from an axis via an SCIAxisInfo object. Please refer to the AxisMarkerAnnotation TextFormatting section to learn more.
SCIAxisMarkerAnnotation.fontStyle Determines the appearance of the text on the marker via the SCIFontStyle object. Please refer to the Styling and Theming article to learn more.
SCIAxisMarkerAnnotation.markerPointSize Allows to specify the length of the pointed end of the marker.
SCIAxisMarkerAnnotation.borderPen Allows to specify the outline color of the marker.
SCIAxisMarkerAnnotation.backgroundBrush Allows to specify the background brush of the marker.

NOTE: To learn more about Annotations in general - please see the Common Annotation Features article.

The SCIAxisMarkerAnnotation can be placed on the X-Axis or the Y-Axis which is specified via the ISCIAnnotation.annotationSurface property. It accepts a member of the SCIAnnotationSurfaceEnum enumeration and it defaults to XAxis for the AxisMarkerAnnotation.

Position of the SCIAxisMarkerAnnotation is defined by the X1 or Y1 coordinate, depending on the axis. Those values can be accessed via the ISCIAnnotation.x1 and ISCIAnnotation.y1 properties.

Also, AxisMarkerAnnotation can be aligned relative to the X1 or Y1 coordinate by setting Anchor Points. For more information about the Anchor Points - refer to the corresponding section Annotations APIs article.

NOTE: The xAxisId and yAxisId must be supplied if you have axis with non-default Axis Ids, e.g. in multi-axis scenario.

Create an AxisMarkerAnnotation

A simple SCIAxisMarkerAnnotation can be added onto a chart using the following code:

// Assume a surface has been created and configured somewhere id<ISCIChartSurface> surface; // Create an AxisMarkerAnnotation SCIAxisMarkerAnnotation *rightMarker = [SCIAxisMarkerAnnotation new]; // Specify a desired position by setting the Y1 coordinate, since the marker is going to be located on an Y axis rightMarker.y1 = @(8); // Allow to interact with the annotation in run-time rightMarker.isEditable = YES; // In a multi-axis scenario, specify the XAxisId and YAxisId rightMarker.xAxisId = BottomAxisId; rightMarker.yAxisId = RightAxisId; // Specify the outline color for the marker rightMarker.borderPen = [[SCISolidPenStyle alloc] initWithColorCode:0xFF4083B7 thickness:1]; // Specify the background color for the marker rightMarker.backgroundBrush = [[SCISolidBrushStyle alloc] initWithColorCode:0xAA4083B7]; // Add the annotation to the Annotations collection of the surface [self.surface.annotations add:rightMarker];
// Assume a surface has been created and configured somewhere let surface: ISCIChartSurface // Create an AxisMarkerAnnotation let rightMarker = SCIAxisMarkerAnnotation() // Specify a desired position by setting the Y1 coordinate, since the marker is going to be located on an Y axis rightMarker.set(y1: 8) // Allow to interact with the annotation in run-time rightMarker.isEditable = true // In a multi-axis scenario, specify the XAxisId and YAxisId rightMarker.xAxisId = BottomAxisId rightMarker.yAxisId = RightAxisId // Specify the outline color for the marker rightMarker.borderPen = SCISolidPenStyle(colorCode: 0xFF4083B7, thickness: 1) // Specify the background color for the marker rightMarker.backgroundBrush = SCISolidBrushStyle(colorCode: 0xAA4083B7) // Add the annotation to the Annotations collection of the surface self.surface.annotations.add(rightMarker)
// Assume a surface has been created and configured somewhere IISCIChartSurface surface; // Create an AxisMarkerAnnotation var rightMarker = new SCIAxisMarkerAnnotation(); // Specify a desired position by setting the Y1 coordinate, since the marker is going to be located on an Y axis rightMarker.Y1Value = 8; // Allow to interact with the annotation in run-time rightMarker.IsEditable = true; // In a multi-axis scenario, specify the XAxisId and YAxisId rightMarker.XAxisId = BottomAxisId; rightMarker.YAxisId = RightAxisId; // Specify the outline color for the marker rightMarker.BorderPen = new SCISolidPenStyle(0xFF4083B7, 1); // Specify the background color for the marker rightMarker.BackgroundBrush = new SCISolidBrushStyle(0xAA4083B7); // Add the annotation to the Annotations collection of the surface Surface.Annotations.Add(rightMarker);

AxisMarkerAnnotation TextFormatting

By default, the axis marker text is formatted by the ISCIAxisCore.textFormatting property. For more information, refer to the Axis Labels - TextFormatting and CursorTextFormatting article.

But you can also override the default behaviour by using textformatting by providing custom the ISCIFormattedValueProvider for your SCIAxisMarkerAnnotation corresponding property.

Let’s see a short example which shows how to use the above:

// Declare custom ISCIFormattedValueProvider @interface AnnotationValueProvider: NSObject<ISCIFormattedValueProvider> @end @implementation AnnotationValueProvider - (id)formatValueWithAxisInfo:(SCIAxisInfo *)axisInfo { return axisInfo != nil ? [NSString stringWithFormat:@“[ — %@ — ]”, axisInfo.axisFormattedDataValue] : nil; } @end … // Provide custom ISCIFormattedValueProvider for the annotation rightMarker.formattedLabelValueProvider = [AnnotationValueProvider new];
// Declare custom ISCIFormattedValueProvider class AnnotationValueProvider: ISCIFormattedValueProvider { func formatValue(with axisInfo: SCIAxisInfo!) -> ISCIString! { return axisInfo != nil ? NSString(string: “[ — \(axisInfo.axisFormattedDataValue!) — ]”) : nil; } } … // Provide custom ISCIFormattedValueProvider for the annotation rightMarker.formattedLabelValueProvider = AnnotationValueProvider()
// Declare custom ISCIFormattedValueProvider class AnnotationValueProvider : ISCIFormattedValueProvider { public override IISCIString FormatValueWithAxisInfo(SCIAxisInfo axisInfo) { return axisInfo != null ? $“[ — {axisInfo.AxisFormattedDataValue} — ]”.ToSciString() : null; } } … // Provide custom ISCIFormattedValueProvider for the annotation rightMarker.FormattedLabelValueProvider = new AnnotationValueProvider();

which will result in the following:

Axis Marker Annotation Formatting

NOTE: To learn more about other Annotation Types, available out of the box in SciChart, please find the comprehensive list in the Annotation APIs article.