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

ChartControl.AnnotationItemsSource Property

Gets or sets the collection of objects used to generate annotations.

Namespace: DevExpress.Xpf.Charts

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

NuGet Package: DevExpress.Wpf.Charts

#Declaration

public IEnumerable AnnotationItemsSource { get; set; }

#Property Value

Type Description
IEnumerable

A collection that is used to generate annotations. The default is null (Nothing in Visual Basic).

#Example

The Chart Control can generate its child elements from their ViewModels. This is useful when the application uses the MVVM architecture and the Chart should contain several chart elements that are bound to data. Use the ChartControl.AnnotationItemsSource property to specify the collection the Chart control utilizes to generate annotations. The ChartControl.AnnotationItemTemplate property allows you to define annotation presentation.

Note

If you have more than one template that can be used to render annotations, you can implement custom logic to choose the required template. To do this, derive from the DataTemplateSelector class, implement the SelectTemplate method that returns a template which meets the required condition, and assign it to the ChartControl.AnnotationItemTemplateSelector property.

public class ChartViewModel {
    public IEnumerable<MyAnnotation> Annotations { get; private set; }
    public ChartViewModel() {        
        Annotations = new Collection<MyAnnotation> {
            new MyAnnotation("Annotation 1", 2012, 6.203) {
                ConnectorLength = 100,
                Angle = -45
            },
            new MyAnnotation("Annotation 2", 2010, 5.7) {
                ConnectorLength = 100,
                Angle = 0
            }
        };
    }
    public class MyAnnotation {
        public string Content { get; set; }
        public AxisXCoordinate XValue { get; set; }
        public AxisYCoordinate YValue { get; set; }
        public double ConnectorLength { get; set; }
        public double Angle { get; set; }
        public MyAnnotation(string content, double xVal, double yVal) {
            Content = content;
            XValue = new AxisXCoordinate() { AxisValue = xVal };
            YValue = new AxisYCoordinate() { AxisValue = yVal };
        }
    }
}
See Also