How to: Customize Chart Titles

  • 2 minutes to read

With DXCharts, you can fully customize the appearance and behavior of chart titles. For example, this sample illustrates how to display a group of check boxes, which control series visibility, in a chart title’s area.

To accomplish this task, it is necessary to define a WrapPanel with a set of CheckBox elements, and bind their check state to a Series.Visible property of the corresponding series. Then this WrapPanel can be placed as a chart title into a ChartControlBase.Titles collection.

View Example

<Window x:Class="CustomChartTitles.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:dxc="http://schemas.devexpress.com/winfx/2008/xaml/charts"
        Title="Custom Chart Titles" Height="380" Width="650">
    <Grid>
        <dxc:ChartControl Name="chart">
            <dxc:ChartControl.Titles>
                <dxc:Title>
                    <WrapPanel Orientation="Vertical">
                        <CheckBox Name="chRed" Foreground="Red" IsChecked="True" FontSize="14">
                            Red
                        </CheckBox>
                        <CheckBox Name="chGreen" Foreground="Green" IsChecked="True" FontSize="14">
                            Green
                        </CheckBox>
                        <CheckBox Name="chBlue" Foreground="Blue" IsChecked="True" FontSize="14">
                            Blue
                        </CheckBox>
                    </WrapPanel>
                </dxc:Title>
            </dxc:ChartControl.Titles>
            <dxc:ChartControl.Diagram>
                <dxc:XYDiagram2D>
                    <dxc:XYDiagram2D.AxisX>
                        <dxc:AxisX2D>
                            <dxc:AxisX2D.Range>
                                <dxc:AxisRange SideMarginsEnabled="False" />
                            </dxc:AxisX2D.Range>
                        </dxc:AxisX2D>
                    </dxc:XYDiagram2D.AxisX>
                    <dxc:XYDiagram2D.Series>
                        <dxc:AreaSeries2D Name="Blue" Brush="Blue" Transparency="0.5" 
                                          Visible="{Binding ElementName=chBlue, Path=IsChecked}">
                            <dxc:AreaSeries2D.Points>
                                <dxc:SeriesPoint Argument="1" Value="0.5" />
                                <dxc:SeriesPoint Argument="2" Value="2" />
                                <dxc:SeriesPoint Argument="3" Value="1.5" />
                            </dxc:AreaSeries2D.Points>
                            <dxc:AreaSeries2D.Label>
                                <dxc:SeriesLabel Visible="False" />
                            </dxc:AreaSeries2D.Label>
                        </dxc:AreaSeries2D>
                        <dxc:AreaSeries2D Name="Red" Brush="Red" Transparency="0.5" 
                                          Visible="{Binding ElementName=chRed, Path=IsChecked}">
                            <dxc:AreaSeries2D.Points>
                                <dxc:SeriesPoint Argument="1" Value="0.3" />
                                <dxc:SeriesPoint Argument="2" Value="1.8" />
                                <dxc:SeriesPoint Argument="3" Value="1.3" />
                            </dxc:AreaSeries2D.Points>
                            <dxc:AreaSeries2D.Label>
                                <dxc:SeriesLabel Visible="False" />
                            </dxc:AreaSeries2D.Label>
                        </dxc:AreaSeries2D>
                        <dxc:AreaSeries2D Name="Green" Brush="Green" Transparency="0.5" 
                                          Visible="{Binding ElementName=chGreen, Path=IsChecked}">
                            <dxc:AreaSeries2D.Points>
                                <dxc:SeriesPoint Argument="1" Value="0.1" />
                                <dxc:SeriesPoint Argument="2" Value="1.6" />
                                <dxc:SeriesPoint Argument="3" Value="1.1" />
                            </dxc:AreaSeries2D.Points>
                            <dxc:AreaSeries2D.Label>
                                <dxc:SeriesLabel Visible="False" />
                            </dxc:AreaSeries2D.Label>
                        </dxc:AreaSeries2D>
                    </dxc:XYDiagram2D.Series>
                </dxc:XYDiagram2D>
            </dxc:ChartControl.Diagram>
        </dxc:ChartControl>
    </Grid>
</Window>