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

Style LegendItems

2 Answers 62 Views
Chart
This is a migrated thread and some comments may be shown as answers.
Grtjn
Top achievements
Rank 1
Grtjn asked on 01 Apr 2010, 08:07 AM
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 Answers, 1 is accepted

Sort by
0
Accepted
Velin
Telerik team
answered on 06 Apr 2010, 08:26 AM
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.
0
Grtjn
Top achievements
Rank 1
answered on 06 Apr 2010, 11:10 AM
Thanks Velin!

Kind regards,

Gertjan
Tags
Chart
Asked by
Grtjn
Top achievements
Rank 1
Answers by
Velin
Telerik team
Grtjn
Top achievements
Rank 1
Share this question
or