The RealTimeChart template consists of a grid container, which lays out the various chart parts/ The grid consists initially of 3 rows and 3 columns. In the middle (row 1, column 1), we have the plot area, which is a FrameworkElement. The PlotArea draws the chart together with the X-axis.
PlotArea Declaration (XAML) Copy Code |
---|
<local:PlotArea |
Y-axes and Y2-axes are rendered in an ItemsControl. There are two ItemsControl instances - one to the left and one to the right of the PlotArea element:
Y-axes Declaration (XAML) Copy Code |
---|
<!-- left Y axes --> <!-- right Y axes --> |
The legend is an ItemsControl as well. It is bound to the SeriesCollection of the chart and is visible when ShowLegend is true. Initially it is placed at the bottom of the chart, in the middle (last grid row, middle grid column):
Legend Declaration (XAML) Copy Code |
---|
<!-- legend template --> |
The title is a TextBlock located at the top:
Title Declaration (XAML) Copy Code |
---|
<TextBlock |
The Y and Y2 axes are rendered by custom ItemsControl, which uses custom AxisRenderer (derived from FrameworkElement). The axes are arranged in a horizontal StackPanel.
The Y-axis Control Template (XAML) Copy Code |
---|
<Style x:Key="YAxisControl" TargetType="{x:Type ItemsControl}" xmlns:x="http://mindfusion.eu"> |
Each item is a StackPanel, which contains a Path Shape and a string. The StackPanel-s are arranged in a WrapPanel. The SeriesToGeometryConverter converts the ScatterType of each Series to a Path.Data object.
The Legend Control Template (XAML) Copy Code |
---|
<Style TargetType="{x:Type local:Legend}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type local:Legend}"> <Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" CornerRadius="{TemplateBinding CornerRadius}" Padding="{TemplateBinding Padding}" Background="{TemplateBinding Background}" Margin="{TemplateBinding Margin}"> <ItemsPresenter /> </Border> </ControlTemplate> </Setter.Value> </Setter> <Setter Property="ItemsPanel"> <Setter.Value> <ItemsPanelTemplate> <WrapPanel Orientation="{Binding Orientation, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:Legend}}}" /> </ItemsPanelTemplate> </Setter.Value> </Setter> <Setter Property="ItemTemplate"> <Setter.Value> <DataTemplate DataType="{x:Type local:Series}"> <StackPanel Orientation="Horizontal" Margin="10, 0"> <Path Stroke="{Binding Stroke}" Fill="{Binding Fill}" Data="{Binding Converter={StaticResource seriesToGeometryConverter}}"></Path> <TextBlock Margin="5,0,0,0" FontFamily="{Binding TitleFontFamily}" FontSize="{Binding TitleFontSize}" Text="{Binding Title}" /> </StackPanel> </DataTemplate> </Setter.Value> </Setter> </Style> |
Here is the entire RealTimeChart template:
RealTimeChart (XAML) Copy Code |
---|
<ResourceDictionary <local:ChartToLegendVisibilityConverter x:Key="chartToLegendVisibilityConverter"/> <Style x:Key="YAxisControl" TargetType="{x:Type ItemsControl}"> <Setter Property="ItemsPanel"> <Setter Property="ItemTemplate"> <Style TargetType="{x:Type local:RealTimeChart}"> <!-- legend template --> <!-- title template --> <!-- left Y axes --> <!-- right Y axes --> <!-- plot area template --> <!-- tooltip template --> <Style TargetType="{x:Type local:Legend}"> <Setter Property="ItemsPanel"> <Setter Property="ItemTemplate"> |