Hide legend of WPF Toolkit chart with more than one data series Hide legend of WPF Toolkit chart with more than one data series wpf wpf

Hide legend of WPF Toolkit chart with more than one data series


There doesn't seem to be an especially clean way. One simple approach is to set the Legend's Width to zero using LegendStyle:

<charting:Chart>    <charting:Chart.LegendStyle>        <Style TargetType="datavis:Legend">            <Setter Property="Width" Value="0" />        </Style>    </charting:Chart.LegendStyle>

A more drastic approach is to replace the ControlTemplate with one that does not include a Legend:

<charting:Chart>    <charting:Chart.Template>        <ControlTemplate TargetType="{x:Type charting:Chart}">            <Border Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Padding="{TemplateBinding Padding}">                <Grid>                    <Grid.RowDefinitions>                        <RowDefinition Height="Auto" />                        <RowDefinition Height="*" />                    </Grid.RowDefinitions>                    <datavis:Title Content="{TemplateBinding Title}" Style="{TemplateBinding TitleStyle}" />                    <chartingprimitives:EdgePanel Name="ChartArea" Style="{TemplateBinding ChartAreaStyle}" Grid.Row="1" Margin="0,15,0,15">                        <Grid Panel.ZIndex="-1" Style="{TemplateBinding PlotAreaStyle}" />                        <Border Panel.ZIndex="10" BorderBrush="#FF919191" BorderThickness="1" />                    </chartingprimitives:EdgePanel>                </Grid>            </Border>        </ControlTemplate>    </charting:Chart.Template>

Use following namespaces:

xmlns:charting="clr-namespace:System.Windows.Controls.DataVisualization.Charting;assembly=System.Windows.Controls.DataVisualization.Toolkit"xmlns:datavis="clr-namespace:System.Windows.Controls.DataVisualization;assembly=System.Windows.Controls.DataVisualization.Toolkit"xmlns:chartingprimitives="clr-namespace:System.Windows.Controls.DataVisualization.Charting.Primitives;assembly=System.Windows.Controls.DataVisualization.Toolkit"


I tried Quarermeister's approach but his has a reference to a "datavis" assembly in the TargetType attribute that I didn't have.

<chartingToolkit:Chart.LegendStyle>    <Style TargetType="Control">        <Setter Property="Width" Value="0" />        <Setter Property="Height" Value="0" />    </Style></chartingToolkit:Chart.LegendStyle>

I also had to add padding to the right side of the chart because without the legend, my x-axis interval labels were extending outside the chart area.


Much more sensible approach...

<charting:LineSeries.LegendItemStyle >  <Style TargetType="{x:Type charting:LegendItem}">     <Setter Property="Visibility" Value="Collapsed"/>  </Style></charting:LineSeries.LegendItemStyle>

Worked better for me than setting values to 0...Cheers!