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

Coloring the Legend Items

5 Answers 232 Views
Chart
This is a migrated thread and some comments may be shown as answers.
GPJ
Top achievements
Rank 1
GPJ asked on 30 Apr 2009, 02:44 PM
I followed the instructions in another forum post for changing the colors of my pie chart and that worked fine, but the legend colors continued to show the original theme colours.

 

 

My XAML inside the grid resources (I only set the first two colors).

 

 
            <SolidColorBrush x:Key="RadialItemStroke" Color="#FF000000"/>  
 
            <telerikStyling:StylesPalette x:Key="{telerikStyling:ThemeResourceKey   
                    ThemeType={x:Type telerikStyling:Office_BlackTheme},   
                    ElementType={x:Type telerikStyling:ChartArea},   
                    ResourceId={x:Static telerikStyling:ResourceHelper.ResourceKeyRadialStyle}}"> 
                <Style TargetType="{x:Type Shape}">  
                    <Setter Property="Stroke" Value="{StaticResource RadialItemStroke}" /> 
                    <Setter Property="StrokeThickness" Value="2" /> 
                    <Setter Property="Fill" Value="{StaticResource WidgetLightGreen}" /> 
                </Style> 
                <Style TargetType="{x:Type Shape}">  
                    <Setter Property="Stroke" Value="{StaticResource RadialItemStroke}" /> 
                    <Setter Property="StrokeThickness" Value="2" /> 
                    <Setter Property="Fill" Value="{StaticResource WidgetOrange}" /> 
                </Style> 
            </telerikStyling:StylesPalette> 

My chart.
            <telerik:RadChart x:Name="ProgressChart"   
                              Margin="4,8,4,4" 
                              VerticalAlignment="Stretch"   
                              HorizontalAlignment="Stretch">  
                <telerik:RadChart.Background> 
                    <SolidColorBrush Color="Transparent"/>  
                </telerik:RadChart.Background> 
            </telerik:RadChart> 
 

Nothing fancy, but the legend doesn't color correctly.  I saw another post that mentionned the data series naming & legend items naming have been decoupled in the latest release - so I am assuming that also the colors were seperated as well, but I can't figure out how to change them.

Greg

5 Answers, 1 is accepted

Sort by
0
Accepted
Ves
Telerik team
answered on 04 May 2009, 09:22 AM
Hello Greg Peter Joyal,

I am afraid this seems to be a bug in the control. I have notified our developers of it, so they will provide a fix. Please, accept our apologies for the inconvenience caused. Your Telerik points have been updated.

Sincerely,
Ves
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Ryan Overton
Top achievements
Rank 2
answered on 01 Oct 2009, 05:07 PM
Is there any news on this issue? Has it been fixed?

I am working with a RadChart line series and have been able to add my own custom legend items, but they are all white. I would like to have them the same color as the lines being produced. Any help would be much appreciated.

Thank you,
Ryan
0
Ves
Telerik team
answered on 05 Oct 2009, 01:01 PM
Hello Ryan,

RadChart will provide the correct colors for the auto-generated legend items.  You will have to provide the style for the custom items by yourself. You can find an example here. You may need to add a value for the Background property of ChartLegendItem.

Sincerely,
Ves
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.
0
Grtjn
Top achievements
Rank 1
answered on 30 Mar 2010, 01:08 PM
Hi,

Is it possible to bind a color to the value of the Property? The color has to come from my database...
For the Piechart I was able to bind a color to each segment of the pie.
   <RadialGradientBrush x:Key="DoughnutMaskBrush" GradientOrigin="0.5,0.5">  
                <GradientStop Color="#33FFFFFF" Offset="0.88"/>  
                <GradientStop Color="#00FFFFFF" Offset="0.66"/>  
                <GradientStop Color="#19FFFFFF" Offset="0.47"/>  
                <GradientStop Offset="0.46"/>  
                <GradientStop Offset="0.89"/>  
            </RadialGradientBrush> 
 
            <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> 
 PieChart1.DefaultSeriesDefinition = new DoughnutSeriesDefinition()  
                {  
                    ShowItemToolTips = true,  
                    ShowItemLabels = false,  
                    ItemToolTipFormat = "#Naam : #Percentage%",  
                    ItemStyle = (this.LayoutRoot.Resources["CustomStyle"] as Style)  
                }; 
 
Now I'm trying to do the same for the legenditems
When adding a color to the value it works fine
PieChart1.DefaultView.ChartLegend.LegendItemStyle = new Style() { TargetType = typeof(ChartLegendItem) };  
                PieChart1.DefaultView.ChartLegend.LegendItemStyle.Setters.Add(new Setter() { Property = Control.BackgroundProperty, Value = new SolidColorBrush(Colors.Cyan) }); 
But when i try to bind a color to the value, nothing happens and the application goes in error.
PieChart1.DefaultView.ChartLegend.LegendItemStyle = new Style() { TargetType = typeof(ChartLegendItem) };  
PieChart1.DefaultView.ChartLegend.LegendItemStyle.Setters.Add(new Setter() { Property = Control.BackgroundProperty, Value = "{Binding DataItem.Kleur}" }); 

Webpage error details

User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0)
Timestamp: Tue, 30 Mar 2010 12:09:51 UTC

Message: Unhandled Error in Silverlight Application
Code: 4004   
Category: ManagedRuntimeError      
Message: System.Exception: Catastrophic failure (Exception from HRESULT: 0x8000FFFF (E_UNEXPECTED))
   at MS.Internal.XcpImports.CheckHResult(UInt32 hr)
   at MS.Internal.XcpImports.SetValue(INativeCoreTypeWrapper obj, DependencyProperty property, DependencyObject doh)
   at System.Windows.DependencyObject.SetValue(DependencyProperty property, DependencyObject doh)
   at System.Windows.FrameworkElement.set_Style(Style value)
   at Telerik.Windows.Controls.Charting.ChartLegend.PrepareContainerForItemOverride(DependencyObject element, Object item)
   at System.Windows.Controls.ItemsControl.MS.Internal.Controls.IGeneratorHost.PrepareItemContainer(DependencyObject container, Object item)
   at System.Windows.Controls.ItemContainerGenerator.System.Windows.Controls.Primitives.IItemContainerGenerator.PrepareItemContainer(DependencyObject container)
   at System.Windows.Controls.ItemsControl.AddVisualChild(Int32 index, DependencyObject container, Boolean needPrepareContainer)
   at System.Windows.Controls.ItemsControl.AddContainers()
   at System.Windows.Controls.ItemsControl.RecreateVisualChildren(IntPtr unmanagedObj)    

Line: 56
Char: 13
Code: 0
URI: http://localhost:52677/pieclickeventTestPage.aspx

Any help here?

Kind regards,

Gertjan

0
Ves
Telerik team
answered on 02 Apr 2010, 07:27 AM
Hi Grtjn,

I can see this question has been answered in another forum thread and it seems it fits your needs.

Kind regards,
Ves
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.
Tags
Chart
Asked by
GPJ
Top achievements
Rank 1
Answers by
Ves
Telerik team
Ryan Overton
Top achievements
Rank 2
Grtjn
Top achievements
Rank 1
Share this question
or