Legend Margin or Padding - Too much space, too high

6 posts, 1 answers
  1. Tim
    Tim avatar
    114 posts
    Member since:
    Aug 2011

    Posted 15 Mar 2012 Link to this post

    Hello!

    I am displaying a legend at the top of a chart. Unfortunately I don't have that much space for displaying the chart so I want it to be as small as possible. Everything is working well, except the fact that the legend has to much space reserved at the top and at the botton. How can I remove the space here? There should be zero pixels above and zero pixels below the chart legend. That would be great! Any ideas? Thanks a lot, Tim.
  2. Tim
    Tim avatar
    114 posts
    Member since:
    Aug 2011

    Posted 15 Mar 2012 Link to this post

    Currently I am using this style:
    <telerik:RadChart.LegendStyle>
                                <Style TargetType="telerik:ChartLegend">
                                    <Setter Property="ItemsPanel" >
                                        <Setter.Value>
                                            <ItemsPanelTemplate>
                                                <StackPanel Orientation="Horizontal" HorizontalAlignment="Right" />
                                            </ItemsPanelTemplate>
                                        </Setter.Value>
                                    </Setter>
                                </Style>
                            </telerik:RadChart.LegendStyle>
  3. DevCraft banner
  4. Sia
    Admin
    Sia avatar
    667 posts

    Posted 20 Mar 2012 Link to this post

    Hello Tim,

    Please try to set the chart legend's margin and padding to be 0:
    Chart.DefaultView.ChartLegend.Margin = new Thickness(0);
    Chart.DefaultView.ChartLegend.Padding = new Thickness(0);

    and remove the chart legend's header:
    Chart.DefaultView.ChartLegend.Header = "";

    I hope that this will help.

    Kind regards,
    Sia
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
  5. Tim
    Tim avatar
    114 posts
    Member since:
    Aug 2011

    Posted 20 Mar 2012 Link to this post

    Hi Sia,

    thanks a lot for your reply. Header was already set to "", setting margin and padding did not change anything - don't know why but I also added the following:
    <Setter Property="Template" >
                                        <Setter.Value>
                <ControlTemplate TargetType="telerik:ChartLegend">                                          <Border Background="{TemplateBinding Background}"
                                                    BorderBrush="{TemplateBinding BorderBrush}"
                                                        BorderThickness="{TemplateBinding BorderThickness}" >
                                                        <Grid Margin="0">                                       <ItemsPresenter />                          </Grid>                 </Border>                           </ControlTemplate>
                                        </Setter.Value>
                                    </Setter>

    There is still a little space but I think I will leave it this way...
    Thanks again! All the best,
    Tim.

  6. Answer
    Sia
    Admin
    Sia avatar
    667 posts

    Posted 22 Mar 2012 Link to this post

    Hello Tim,

    Actually the default template is as follows:
    <ControlTemplate TargetType="telerikCharting:ChartLegend">
        <Border Background="{TemplateBinding Background}"
                BorderBrush="{TemplateBinding BorderBrush}"
                BorderThickness="{TemplateBinding BorderThickness}" >
            <Grid Margin="{TemplateBinding Padding}">
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="*" />
                </Grid.RowDefinitions>
                <ContentControl Foreground="{TemplateBinding Foreground}"
                           HorizontalAlignment="Stretch"
                           HorizontalContentAlignment="Stretch"
                           FontWeight="{TemplateBinding HeaderFontWeight}"
                           Content="{TemplateBinding Header}"
                           ContentTemplate="{TemplateBinding HeaderTemplate}"/>
                <ItemsPresenter Grid.Row="1"
                           HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                           VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
            </Grid>
        </Border>
    </ControlTemplate>

    You can see that the Margin that you set to be 0 is template-binded to the Padding property of the control. That is why I said that you need to set the Padding to be 0. Such setting should have the same effect.
    Nevertheless we are happy to hear that you managed to resolve your issue.

    All the best,
    Sia
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
  7. Tim
    Tim avatar
    114 posts
    Member since:
    Aug 2011

    Posted 23 Mar 2012 Link to this post

    Hello Sia,

    thanks for your input and clarifying!
    All the best,
    Tim.
Back to Top
DevCraft banner