Style LegendItems

3 posts, 1 answers
  1. Grtjn
    Grtjn avatar
    129 posts
    Member since:
    Feb 2010

    Posted 01 Apr 2010 Link to this post

    Hi everyone,

    I was able to change the color of the slices in my piechart using a style.
    The colors of this pie have to come from the database and I could do this by using Fill="{Binding DataItem.Kleur}"
    <Style x:Key="CustomStyle" TargetType="Telerik_Windows_Controls_Charting:Doughnut">  
                    <Setter Property="Template" > 
                        <Setter.Value> 
                            <ControlTemplate TargetType="Telerik_Windows_Controls_Charting:Doughnut">  
                                <Canvas> 
                                    <Ellipse Clip="{TemplateBinding FigurePath}"   
                                             Width="{TemplateBinding ItemActualWidth}" 
                                             Height="{TemplateBinding ItemActualHeight}" 
                                             StrokeThickness="0" 
                                             Fill="{Binding DataItem.Kleur}" /> 
                                    <Path x:Name="PART_DefiningGeometry"   
                                          Data="{TemplateBinding FigurePath2}" 
                                          Fill="Transparent" 
                                          Style="{TemplateBinding ItemStyle}" /> 
                                    <Ellipse Clip="{TemplateBinding FigurePath3}"   
                                             Fill="{StaticResource DoughnutMaskBrush}"   
                                             Width="{TemplateBinding ItemActualWidth}" 
                                             Height="{TemplateBinding ItemActualHeight}"/>  
                                    <Canvas.RenderTransform> 
                                        <ScaleTransform x:Name="PART_AnimationTransform" ScaleX="0" ScaleY="0" /> 
                                    </Canvas.RenderTransform> 
                                </Canvas> 
                            </ControlTemplate> 
                        </Setter.Value> 
                    </Setter> 
                </Style> 

    My question is now how I can change the color of my LegendItems as well. And this by using a style, because when i use stylespalette to change the colors I can't get thos colors from my database..
    Anyone can help me plz ?

    Kind regards,

    Gertjan
  2. Answer
    Velin
    Admin
    Velin avatar
    391 posts

    Posted 06 Apr 2010 Link to this post

    Hello Grtjn,

    Here is how you could use the same approach for the legend items:
    <Style x:Name="LegendItemStyle"
                    TargetType="telerikCharting:ChartLegendItem">
                    <Setter Property="Padding" Value="5,0,5,0" />
                    <Setter Property="Margin" Value="0,3,0,2" />
                    <Setter Property="Template" >
                        <Setter.Value>
                            <ControlTemplate TargetType="telerikCharting:ChartLegendItem">
                                <Grid HorizontalAlignment="Stretch" VerticalAlignment="Top">
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="Auto" />
                                        <ColumnDefinition />
                                    </Grid.ColumnDefinitions>
                                    <Path x:Name="PART_LegendItemMarker"
                                 Width="16"
                                 Height="16"
                                 Margin="{TemplateBinding Margin}"
                                 Style="{TemplateBinding ItemStyle}"
                                 Fill="{Binding DataItem.Color}"
                                 Stretch="Fill">
                                        <Path.Data>
                                            <PathGeometry x:Name="PART_ItemMarkerGeometry" />
                                        </Path.Data>
                                    </Path>                             
     
                                    <TextBlock Grid.Column="1"
                                 Padding="{TemplateBinding Padding}"
                                 Margin="{TemplateBinding Margin}"
                                 Foreground="{TemplateBinding Foreground}"
                                 Text="{TemplateBinding Label}" />
                                </Grid>
                            </ControlTemplate>
                        </Setter.Value>
                    </Setter>
                </Style>
     
     
    RadChart1.DefaultView.ChartLegend.LegendItemStyle = this.LegendItemStyle;


    Sincerely yours,
    Velin
    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.
  3. Grtjn
    Grtjn avatar
    129 posts
    Member since:
    Feb 2010

    Posted 06 Apr 2010 Link to this post

    Thanks Velin!

    Kind regards,

    Gertjan
Back to Top