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

Legend height "maximized"

1 Answer 49 Views
Chart
This is a migrated thread and some comments may be shown as answers.
Simon Flachsbart
Top achievements
Rank 1
Simon Flachsbart asked on 25 Jan 2010, 12:32 PM
Hi there,

I tried to restyle the legend of my chart area.
I have two styles to define. First one is, that the legend only appears when a togglebutton (outside of the chart) is clicked. The legend position is over the whole size of the chart. For this reason i override the chart template as follows:
<ControlTemplate x:Key="_chartControlTemplate" TargetType="{x:Type telerik:RadChart}">                 
 <Grid Background="{TemplateBinding Background}"
  <Grid x:Name="PART_DefaultLayoutGrid"
   <Grid.ColumnDefinitions> 
    <ColumnDefinition Width="Auto"/> 
   </Grid.ColumnDefinitions> 
   <Grid.RowDefinitions> 
    <RowDefinition Height="Auto"/> 
    <RowDefinition Height="*"/> 
   </Grid.RowDefinitions> 
   <ContentPresenter x:Name="PART_DefaultChartTitleContainer" Grid.Column="0" Grid.Row="0" Content="{TemplateBinding Content}" ContentStringFormat="{TemplateBinding ContentStringFormat}" ContentTemplate="{TemplateBinding ContentTemplate}"/> 
   <ContentPresenter x:Name="PART_DefaultChartAreaContainer" Grid.Column="0" Grid.Row="1" Content="{TemplateBinding Content}" ContentStringFormat="{TemplateBinding ContentStringFormat}" ContentTemplate="{TemplateBinding ContentTemplate}"/> 
   <ContentPresenter x:Name="PART_DefaultChartLegendContainer" Grid.Column="0" Grid.Row="0" Grid.RowSpan="2" Content="{TemplateBinding Content}" ContentStringFormat="{TemplateBinding ContentStringFormat}" Visibility="{Binding ElementName=LegendVisibilityButton, Path=IsChecked, Converter={StaticResource legendConverter}}"/> 
  </Grid> 
  <ContentPresenter Height="Auto" Width="Auto" Content="{TemplateBinding Content}" ContentStringFormat="{TemplateBinding ContentStringFormat}" ContentTemplate="{TemplateBinding ContentTemplate}"/> 
 </Grid> 
</ControlTemplate> 

The second style is, that the legend is placed between the title and the chartarea.
Therefore i override the chart template and set the legendstyle to the chart:
<ControlTemplate x:Key="_chartControlTemplate" TargetType="{x:Type telerik:RadChart}">                 
 <Grid Background="{TemplateBinding Background}"
  <Grid x:Name="PART_DefaultLayoutGrid"
   <Grid.ColumnDefinitions> 
    <ColumnDefinition Width="Auto"/> 
   </Grid.ColumnDefinitions> 
   <Grid.RowDefinitions> 
    <RowDefinition Height="Auto"/> 
    <RowDefinition Height="Auto"/> 
    <RowDefinition Height="*"/> 
   </Grid.RowDefinitions> 
   <ContentPresenter x:Name="PART_DefaultChartTitleContainer" Grid.Column="0" Grid.Row="0" Content="{TemplateBinding Content}" ContentStringFormat="{TemplateBinding ContentStringFormat}" ContentTemplate="{TemplateBinding ContentTemplate}"/> 
   <ContentPresenter x:Name="PART_DefaultChartAreaContainer" Grid.Column="0" Grid.Row="2" Content="{TemplateBinding Content}" ContentStringFormat="{TemplateBinding ContentStringFormat}" ContentTemplate="{TemplateBinding ContentTemplate}"/> 
   <ContentPresenter x:Name="PART_DefaultChartLegendContainer" Grid.Column="0" Grid.Row="1" Content="{TemplateBinding Content}" ContentStringFormat="{TemplateBinding ContentStringFormat}" Visibility="{Binding ElementName=LegendVisibilityButton, Path=IsChecked, Converter={StaticResource legendConverter}}"/> 
  </Grid> 
  <ContentPresenter Height="Auto" Width="Auto" Content="{TemplateBinding Content}" ContentStringFormat="{TemplateBinding ContentStringFormat}" ContentTemplate="{TemplateBinding ContentTemplate}"/> 
 </Grid> 
</ControlTemplate> 

<
Style x:Key="_chartLegendStyle" TargetType="{x:Type telerik:ChartLegend}"
 <Setter Property="Template"
   . 
   . 
   . 
 <Setter.Value> 
 <Setter Property="ItemsPanel"
  <Setter.Value> 
   <ItemsPanelTemplate > 
    <StackPanel IsItemsHost="True" Orientation="Horizontal"/> 
   </ItemsPanelTemplate> 
  </Setter.Value> 
 </Setter> 
 <Setter Property="HeaderTemplate"
    . 
    . 
    . 
 </Setter> 
</Style> 

Everything works fine except the height of the legend. In both cases the height is filled to any fixed size. I want to set the height of the legend to auto that it just uses the space it needs. Therefore I tried to override the VerticalAlignment to Center as the MinHeight to 100 but nothing seems to be working.

Maybe this is the same issue I have with the size of the chart it self. I am not able to stlye the view that contains the chart that it shrinks with the window. Growing seems to have no problem but shrinking is not possible. (Defaultsize of the chart is around 600x800)

1 Answer, 1 is accepted

Sort by
0
Giuseppe
Telerik team
answered on 28 Jan 2010, 12:17 PM
Hi Simon Flachsbart,

Unfortunately we are unable to reproduce the problematic behavior neither with the height of the chart legend, nor with the size itself.

Please review the attached sample application that demonstrates our observations -- you can play with the legend margin / padding values but generally the legend does not stretch over the space that in needs. Also, we are able  to shrink the chart control without a problem.

Let us know if the problem persists.


Regards,
Manuel
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
Chart
Asked by
Simon Flachsbart
Top achievements
Rank 1
Answers by
Giuseppe
Telerik team
Share this question
or