This is a migrated thread and some comments may be shown as answers.

Can't not display ChartLegend header

1 Answer 65 Views
Chart
This is a migrated thread and some comments may be shown as answers.
Adam Petaccia
Top achievements
Rank 1
Adam Petaccia asked on 20 Jul 2010, 10:39 PM
The RadChart sets its ChartLegend.Header to the helpful string "Legend". My users don't require that text, and in the interest of space, I've tried to remove but am unable to completely do so. Setting ChartLegend.Header to null still renders the text "Legend".
Setting it to the empty string doesn't help, as it still renders the empty string:

Actual result
+------------
|
| o Item1   o Item2   o Item3
+------------

Desired result
+------------
| o Item1   o Item2   o Item3
+------------

How do I achieve this effect?

1 Answer, 1 is accepted

Sort by
0
Sia
Telerik team
answered on 21 Jul 2010, 10:37 AM
Hello Adam Petaccia,

You need to retemplate your ChartLegend. In order to do that just add the following Style in your resources:
xmlns:telerik="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.Charting"
xmlns:controls="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls"
xmlns:charting="clr-namespace:Telerik.Windows.Controls.Charting;assembly=Telerik.Windows.Controls.Charting">
    <UserControl.Resources>
        <SolidColorBrush x:Key="LegendForeground" Color="#FF000000" />
        <LinearGradientBrush x:Key="LegendBackground" EndPoint="1.96,0.5" StartPoint="-0.96,0.5">
            <GradientStop Color="#FFB5B5B5"/>
            <GradientStop Color="#FFF0F0F0" Offset="0.5"/>
        </LinearGradientBrush>
        <SolidColorBrush x:Key="LegendBorderBrush" Color="#FF848484" />
        <Thickness x:Key="LegendBorderThickness">1</Thickness>
         
        <Style x:Key="CustomLegend" TargetType="charting:ChartLegend">
            <Setter Property="Background" Value="{StaticResource LegendBackground}" />
            <Setter Property="Padding" Value="10,10,10,5" />
            <Setter Property="Margin" Value="0"/>
            <Setter Property="BorderBrush" Value="{StaticResource LegendBorderBrush}" />
            <Setter Property="BorderThickness" Value="{StaticResource LegendBorderThickness}" />
            <Setter Property="TitleFontWeight" Value="Bold" />
            <Setter Property="Template" >
                <Setter.Value>
                    <ControlTemplate TargetType="charting:ChartLegend">
                        <Border
                            Background="{TemplateBinding Background}"
                            BorderBrush="{TemplateBinding BorderBrush}"
                            BorderThickness="{TemplateBinding BorderThickness}" >
                            <Grid Margin="{TemplateBinding Padding}">
                                <ItemsPresenter />
                            </Grid>
                        </Border>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
            <Setter Property="ItemsPanel" >
                <Setter.Value>
                    <ItemsPanelTemplate>
                        <controls:RadWrapPanel Orientation="{Binding ItemsPanelOrientation}" />
                    </ItemsPanelTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </UserControl.Resources>
 
    <Grid x:Name="LayoutRoot" Background="Red">
        <telerik:RadChart x:Name="RadChart1" />
    </Grid>

and set it to your Legend by having the following line in your code-behind:
RadChart1.DefaultView.ChartLegend.Style = this.Resources["CustomLegend"] as Style;

You can reduce the Legend's padding also if you need more space. The brushes above are used in our default "Office Black" theme. If you have set another theme, just let me know.

Greetings,
Sia
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
Chart
Asked by
Adam Petaccia
Top achievements
Rank 1
Answers by
Sia
Telerik team
Share this question
or