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

Legend Margin or Padding - Too much space, too high

5 Answers 186 Views
Chart
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Tim
Top achievements
Rank 1
Tim asked on 15 Mar 2012, 07:41 PM
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.

5 Answers, 1 is accepted

Sort by
0
Tim
Top achievements
Rank 1
answered on 15 Mar 2012, 07:44 PM
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>
0
Sia
Telerik team
answered on 20 Mar 2012, 09:48 AM
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 >>
0
Tim
Top achievements
Rank 1
answered on 20 Mar 2012, 10:13 AM
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.

0
Accepted
Sia
Telerik team
answered on 22 Mar 2012, 10:32 AM
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 >>
0
Tim
Top achievements
Rank 1
answered on 23 Mar 2012, 09:00 AM
Hello Sia,

thanks for your input and clarifying!
All the best,
Tim.
Tags
Chart
Asked by
Tim
Top achievements
Rank 1
Answers by
Tim
Top achievements
Rank 1
Sia
Telerik team
Share this question
or