Skip to main content

ChartControl.AnnotationItemsSource Property

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

Namespace: DevExpress.Xpf.Charts

Assembly: DevExpress.Xpf.Charts.v24.1.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.

<Window.DataContext>
    <viewModel:ChartViewModel/>
</Window.DataContext>
<Grid>
    <dxc:ChartControl AnnotationItemsSource="{Binding Path=Annotations, Mode=OneTime}" >
        <!-- Other chart settings are skipped. -->
        <dxc:ChartControl.AnnotationItemTemplate>
            <DataTemplate>
                <dxc:Annotation Content="{Binding Content}">
                    <dxc:Annotation.ShapePosition>
                        <dxc:RelativePosition 
                            Angle="{Binding Angle}" 
                            ConnectorLength="{Binding ConnectorLength}"/>
                    </dxc:Annotation.ShapePosition>
                    <dxc:Annotation.AnchorPoint>
                        <dxc:PaneAnchorPoint AxisXCoordinate="{Binding XValue}" 
                                             AxisYCoordinate="{Binding YValue}"/>
                    </dxc:Annotation.AnchorPoint>
                </dxc:Annotation>
            </DataTemplate>
        </dxc:ChartControl.AnnotationItemTemplate>
    </dxc:ChartControl>
</Grid>
See Also