Click or drag to resize

Annotations

S# provides the ability to add annotations to the chart in the form of text, lines, etc.

Adding annotations is the same as adding any other information to the chart. First you need to create ChartAnnotation and add it to the chart area:

C#
var _annotation = new ChartAnnotation { Type = ChartAnnotationTypes.BoxAnnotation };
Chart.AddElement(chartArea, _annotation);

After that, you need to initialize a new instance of the ChartDrawDataAnnotationData, class, in which to describe the annotation and pass it to the ChartDraw(ChartDrawData) method for drawing on the chart:

C#
var data = new ChartDrawData.AnnotationData
{
    X1 = new DateTimeOffset(2017, 10, 04,0,0,0, TimeSpan.FromHours(1)),
    X2 = new DateTimeOffset(2017, 10, 05, 0, 0, 0, TimeSpan.FromHours(1)),
    Y1 = 190m,
    Y2 = 191m,
    IsVisible = true,
    Fill = new SolidColorBrush(Color.FromRgb((byte)RandomGen.GetInt(0, 255), (byte)RandomGen.GetInt(0, 255), (byte)RandomGen.GetInt(0, 255))),
    Stroke = new SolidColorBrush(Color.FromRgb((byte)RandomGen.GetInt(0, 255), (byte)RandomGen.GetInt(0, 255), (byte)RandomGen.GetInt(0, 255))),
    Foreground = new SolidColorBrush(Color.FromRgb((byte)RandomGen.GetInt(0, 255), (byte)RandomGen.GetInt(0, 255), (byte)RandomGen.GetInt(0, 255))),
    Thickness = new Thickness(1),
    Text = "New annotation",
    HorizontalAlignment = HorizontalAlignment.Stretch,
    VerticalAlignment = VerticalAlignment.Stretch,
    LabelPlacement = LabelPlacement.Axis,
    ShowLabel = true,
    CoordinateMode = AnnotationCoordinateMode.Absolute,
};

var drawData = new ChartDrawData();
drawData.Add(_annotation, data);
Chart.Draw(drawData);