Skip to main content

DevExpress v24.2 Update — Your Feedback Matters

Our What's New in v24.2 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

Annotation Class

An additional note that can be anchored to a chart, pane, or series point.

Namespace: DevExpress.Xpf.Charts

Assembly: DevExpress.Xpf.Charts.v24.2.dll

NuGet Package: DevExpress.Wpf.Charts

#Declaration

public class Annotation :
    ChartNotificationElement,
    IWeakEventListener,
    IHitTestableElement,
    IInteractiveElement,
    IScrollBarAnnotation

The following members return Annotation objects:

#Remarks

For more information about annotations, refer to the following help topic: Annotations.

#Examples

#Add an Annotation in Markup

This example demonstrates how to anchor an annotation to a series point.

To do this, specify the SeriesPointAnchorPoint.SeriesPoint property.

<dxc:Annotation Content="Annotation #1">
    <dxc:Annotation.AnchorPoint>
        <dxc:SeriesPointAnchorPoint SeriesPoint="{Binding ElementName=seriesPoint}"/>
    </dxc:Annotation.AnchorPoint>
    <dxc:Annotation.ShapePosition>
        <dxc:RelativePosition Angle="60" 
                              ConnectorLength="50"/>
    </dxc:Annotation.ShapePosition>
</dxc:Annotation>

#Add an Annotation in Code

The following example creates an annotation that is anchored to a pane.

<dxc:ChartControl x:Name="chartControl">
    <dxc:XYDiagram2D x:Name="diagram">
        <dxc:XYDiagram2D.SecondaryAxesX>
            <dxc:SecondaryAxisX2D x:Name="xAxis"/>
        </dxc:XYDiagram2D.SecondaryAxesX>
        <dxc:XYDiagram2D.SecondaryAxesY>
            <dxc:SecondaryAxisY2D x:Name="yAxis"/>
        </dxc:XYDiagram2D.SecondaryAxesY>
        <dxc:XYDiagram2D.Panes>
            <dxc:Pane x:Name="pane"/>
        </dxc:XYDiagram2D.Panes>
        <!--...-->
    </dxc:XYDiagram2D>
</dxc:ChartControl>
using DevExpress.Xpf.Charts;
//...
private void Window_Loaded(object sender, RoutedEventArgs e) {
    Annotation annotation = new Annotation();
    annotation.Content = "Annotation";
    annotation.AnchorPoint = new PaneAnchorPoint {
        AxisXCoordinate = new AxisXCoordinate { AxisValue = new TimeSpan(0, 0, 5), Axis = xAxis },
        AxisYCoordinate = new AxisYCoordinate { AxisValue = 100, Axis = yAxis }, 
        Pane = pane
    };
    annotation.ShapePosition = new RelativePosition { Angle = 30, ConnectorLength = 60 };
    chartControl.Annotations.Add(annotation);
}

If the chart is bound to data and you want to anchor an annotation to a series point, use the ChartControl.BoundDataChanged event to access the point collection. The following example creates an annotation for each point of a spline series.

<dxc:ChartControl x:Name="chartControl" 
                  BoundDataChanged="chartControl_BoundDataChanged">
    <dxc:XYDiagram2D x:Name="diagram">
        <dxc:SplineSeries2D>
            <!--...-->
        </dxc:SplineSeries2D>
    </dxc:XYDiagram2D>
</dxc:ChartControl>
using DevExpress.Xpf.Charts;
//...
private void chartControl_BoundDataChanged(object sender, RoutedEventArgs e) {
    SplineSeries2D series = (SplineSeries2D)diagram.Series[0];
    if (series.Points.Count > 0) {
        for (int i = 0; i < series.Points.Count; i++) {
            chartControl.Annotations.BeginInit();
            Annotation annotation = new Annotation() { 
                Content = series.Points[i].Value.ToString() 
            };
            annotation.AnchorPoint = new SeriesPointAnchorPoint() { 
                SeriesPoint = series.Points[i] 
            };
            annotation.ShapePosition = new RelativePosition() { 
                Angle = 0, 
                ConnectorLength = 0 
            };
            chartControl.Annotations.Add(annotation);
            chartControl.Annotations.EndInit();
        }
    }
}

#Inheritance

Show 11 items
See Also