Chart legends in WPF Toolkit June 2009 Release

Jun 29, 2009 at 6:14 AM

Really cool release - finally figured how to use and got it to work.  Thank you.

Now, is there any way to hide a legend, especially on the bar charts?

Thanks in advance.

Jun 29, 2009 at 9:17 PM

Try editing the default control template for the chart.  Here is an example of the default chart control template with the title, legend and border commented out. 

<Setter Property="Template">
                        <ControlTemplate TargetType="chartingToolkit:Chart">
                            <Border Background="{TemplateBinding Background}"
                        BorderBrush="{TemplateBinding BorderBrush}"
                        BorderThickness="{TemplateBinding BorderThickness}"
                                        <RowDefinition Height="Auto"/>
                                        <RowDefinition Height="*"/>

                                    <!--<visualizationToolkit:Title Style="{TemplateBinding TitleStyle}"
                                                  Content="{TemplateBinding Title}" />-->

                                    <Grid Margin="0,15,0,15"
                                            <ColumnDefinition Width="*" />
                                            <ColumnDefinition Width="Auto" />
                                        <!--<visualizationToolkit:Legend x:Name="Legend"
                                               Style="{TemplateBinding LegendStyle}"
                                               Title="{TemplateBinding LegendTitle}" />-->
                                        <chartingprimitives:EdgePanel x:Name="ChartArea"
                                               Style="{TemplateBinding ChartAreaStyle}">
                                            <Grid Style="{TemplateBinding PlotAreaStyle}"
                                      Canvas.ZIndex="-1" />

                                            <!-- I removed the border-->
                                            <!--<Border Canvas.ZIndex="10"
                                        BorderThickness="1" />-->


 Of course you'll need to have the chartingprimitives namespace added, as well as throw this bit of code in a <Style> resource somewhere...  Hope that helps.

Jun 30, 2009 at 10:48 PM

Thank you so much.  It works like a charm.


Oct 22, 2009 at 10:54 AM

Hi, I'm fairly new to WPF. I'm trying to accomplish the very same thing. But I always get an error with following:

<UserControl.Resources> --> I add this to these resources, maybe wrong ?

<Setter Property="Template"> --> this gives the following error:

'Template' member is not valid because it does not have a qualifying type name.

Can anyone help me with this ?


Jan 19, 2010 at 9:07 PM

Where is this control template to be found?

Also if possible where can I find information describing how the idea of templates fits into the idea of charting?

Thanks in advance.


Jan 20, 2010 at 4:59 AM

A template has to be included inside a style.  The style either has to be included with the object like the bar chart where it is to be used, or you have to specify the type of target to which it applies.  You can then specify the style in the Window.Resources of the same xamle file containing the object or make it available for other xaml files to use.

e.g. the code given above can be included as is with the xaml for the bar chart to which it belongs.

Jan 20, 2010 at 5:03 AM
kyle8086 wrote:

Where is this control template to be found?

Also if possible where can I find information describing how the idea of templates fits into the idea of charting?

Thanks in advance.


A template has to be included inside a style.  Every control has a style associated with it and there are other types of templates available that will determine the type of objects displayed inside a list, for example.

You can use Microsoft Expresson Blend to look at the insides of all controls.  It will give you the styles and templates in use.

Jan 20, 2010 at 8:45 PM

Thanks for your help. Using Blinder to edit a copy of the control's template it became obvious how to make the adjustments as outlined in this discussion.

For others as new as I, it is safe to discard all of the other styles that manifest in the copy of the template reducing it to just what is seen above in this post. Discarding the other information does not seem to hurt anything.


May 25, 2010 at 5:52 PM

When I try to modify the Template, I keep getting this error message, "Cannot find the static member 'LegendStyleProperty' on the type 'AxisLabel'. What exactly does that mean? There doesn't appear to be such a property that can be applied to the AxisLabel. Any thoughts would be greatly appreciated. I am simply trying to remove the legend from the chart either through xaml or code-behind. Doesn't seem like it should be so elusive to do such a simple thing. Thanks in advance.

Nov 9, 2010 at 3:50 PM

Here's another way to hide the legend without having to re-template the entire chart:

<Style x:Key="LegendStyle" TargetType="Control">
    <!-- setting Visibility to Collapsed does not work -->
    <Setter Property="Template" Value="{x:Null}"/>


<charting:Chart LegendStyle="{StaticResource LegendStyle}">


Don't ask me why setting Visibility to Collapsed does not work (at least, in my silghtly outdated build).

Jan 5, 2011 at 2:41 PM
Edited Jan 5, 2011 at 2:44 PM

You can use the following code to hide the Legend for chart having one or multiple series

                        <Style TargetType="{x:Type visual:Legend}">
                            <Setter Property="BorderBrush" Value="Transparent"></Setter>
                            <Setter Property="Background" Value="Transparent"></Setter>


hope this helps :)