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

RadChart Series color

7 Answers 391 Views
Chart
This is a migrated thread and some comments may be shown as answers.
MacKenzie Mickelsen
Top achievements
Rank 1
MacKenzie Mickelsen asked on 01 Dec 2009, 11:32 PM
Hello all

 I am trying to customize the legend of the chart. So I am building my own ChartLegendItem objects. I am running into a problem however in that I don't know the color of the series associated with the new legend item. I have tried to read the value like this:

ChartControl.InnerChart.DefaultView.ChartArea.DataSeries[i].Definition.Appearance.Fill

However the fill, backgroud, foreground, and strock properites are all null. So I get these white boxes which look crappy. Is there a way for me to read this and get it working right? Any assistance would be greatly appreciate

Thanks in advance
MacKenzie

p.s. Here is the code where I am building the legend

 

if

(ChartControl.InnerChart != null)

 

{

 

    if (ChartControl.InnerChart.DefaultView.ChartArea.DataSeries.Count > 0)

 

    {

 

        //Add A legend Item for each unit series

 

 

 

 

 

        for (int i = 0; i < ChartControl.InnerChart.DefaultView.ChartArea.DataSeries.Count; i++)

 

        {

 

            ChartLegendItem item = new ChartLegendItem() { Label = ChartControl.InnerChart.DefaultView.ChartArea.DataSeries[i].Label,Background = ChartControl.InnerChart.DefaultView.ChartArea.DataSeries[i].Definition.Appearance.Fill };

 

            ChartControl.InnerChart.DefaultView.ChartLegend.Items.Add(item);

        }

    }

}

7 Answers, 1 is accepted

Sort by
0
Velin
Telerik team
answered on 04 Dec 2009, 03:52 PM
Hi MacKenzie Mickelsen,

Unfortunately, there is no easy way to extract the colors of the visual series and use it to manually generate legend items. There is a workaround though. You can set the color of your series using the appearance API exposed by the SeriesDefinition object and set exactly the same color to the legend item for each visual series. Here is a sample code demonstrating how to use the appearance API:
ISeriesDefinition def = new LineSeriesDefinition();
def.Appearance.Fill = new SolidColorBrush(Colors.Yellow);
def.Appearance.Foreground = new SolidColorBrush(Colors.Green);
def.Appearance.Stroke = new SolidColorBrush(Colors.White);

Hope this will help.

Sincerely yours,
Velin
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
Denny
Top achievements
Rank 1
answered on 26 Feb 2010, 04:52 PM
Velin,

Could you expand on your code a bit. We are trying something similar.
0
Velin
Telerik team
answered on 04 Mar 2010, 07:54 AM
Hello Denny,

As mentioned in my previous post, with the current official version of the control there is no easy way to customize series appearance and keep the legend items in sync. In the upcoming version, however, we will introduce a convenient API to do customize the default colors of both the series and the legend using code like this:
RadChart1.PaletteBrushes.Add(new SolidColorBrush(Colors.Green));

This new version is expected later this month.

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
Odd Veibust
Top achievements
Rank 1
answered on 14 May 2010, 12:26 PM
Hi.

We're having a little trouble setting the PaletteBrushes on the chart, can't find this property on the RadChart control. Can you provide some info? Am I missing something?


#region Usings  
 
using System.Collections.Generic;  
using Client.CapacityService;  
using Client.Model;  
using Telerik.Windows.Controls;  
using Telerik.Windows.Controls.Charting;
#endregion  
 
namespace Client.Views  
{  
    public partial class GraphView  
    {  
        private ModelLocator _modelLocator = ModelLocator.Instance();  
 
        public GraphView()  
        {  
            InitializeComponent();  
 
            DataContext = _modelLocator;
 
            //RadChart1.PaletteBrushes <---- No such property 
        }  
    }  
        <telerikChart:RadChart x:Name="RadChart1" ItemsSource="{Binding ProductionLines, Mode=OneWay}">  
            <telerikChart:RadChart.SeriesMappings> 
                <telerikCharting:SeriesMapping LegendLabel="Produced">  
                    <telerikCharting:SeriesMapping.SeriesDefinition> 
                        <telerikCharting:StackedBar100SeriesDefinition StackGroupName="Stack1" /> 
                    </telerikCharting:SeriesMapping.SeriesDefinition> 
                    <telerikCharting:SeriesMapping.ItemMappings> 
                        <telerikCharting:ItemMapping FieldName="Produced" DataPointMember="YValue" /> 
                        <telerikCharting:ItemMapping FieldName="Description" DataPointMember="XCategory" /> 
                    </telerikCharting:SeriesMapping.ItemMappings> 
                </telerikCharting:SeriesMapping> 
                <telerikCharting:SeriesMapping LegendLabel="Unused">  
                    <telerikCharting:SeriesMapping.SeriesDefinition> 
                        <telerikCharting:StackedBar100SeriesDefinition StackGroupName="Stack1" /> 
                    </telerikCharting:SeriesMapping.SeriesDefinition> 
                    <telerikCharting:SeriesMapping.ItemMappings> 
                        <telerikCharting:ItemMapping FieldName="UnusedProductionCapcity" DataPointMember="YValue" /> 
                        <telerikCharting:ItemMapping FieldName="Description" DataPointMember="XCategory" /> 
                    </telerikCharting:SeriesMapping.ItemMappings> 
                </telerikCharting:SeriesMapping> 
                <telerikCharting:SeriesMapping LegendLabel="Reduction">  
                    <telerikCharting:SeriesMapping.SeriesDefinition> 
                        <telerikCharting:StackedBar100SeriesDefinition StackGroupName="Stack1" /> 
                    </telerikCharting:SeriesMapping.SeriesDefinition> 
                    <telerikCharting:SeriesMapping.ItemMappings> 
                        <telerikCharting:ItemMapping FieldName="DueToError" DataPointMember="YValue" /> 
                        <telerikCharting:ItemMapping FieldName="Description" DataPointMember="XCategory" /> 
                    </telerikCharting:SeriesMapping.ItemMappings> 
                </telerikCharting:SeriesMapping> 
            </telerikChart:RadChart.SeriesMappings> 
        </telerikChart:RadChart> 
 
0
Odd Veibust
Top achievements
Rank 1
answered on 18 May 2010, 01:49 PM
Just forget my last question, binaries were not refreshed in project. My apoligies.
0
cmr
Top achievements
Rank 1
answered on 18 Jun 2010, 06:11 PM
Reply to Velin's post on March 4, 2010:

How do the PaletteBrushes stay in color sync with SeriesMappings?  In our code, we are still showing discrepancies with asynchronous calls to data.  Whichever values return first is assigned the first color in PaletteBrushes rather than based on SeriesMappings (...and it must be color coded accurately).

// Success is color coded to green. 
SolidColorBrush greenBrush = new SolidColorBrush(); 
greenBrush.Color = Color.FromArgb(255, 19, 130, 26); 
 
// Error is color coded to red. 
SolidColorBrush redBrush = new SolidColorBrush(); 
redBrush.Color = Color.FromArgb(255, 255, 29, 0); 
 
feedsChart.PaletteBrushes.Add(greenBrush); 
feedsChart.PaletteBrushes.Add(redBrush); 
 
// Success SeriesMapping 
SeriesMapping successSeriesMapping = new SeriesMapping(); 
   ... 
feedsChart.SeriesMappings.Add(goodSeriesMapping);   
 
// Error SeriesMapping         
SeriesMapping errorSeriesMapping = new SeriesMapping(); 
   ... 
feedsChart.SeriesMappings.Add(errorSeriesMapping);   

0
Velin
Telerik team
answered on 24 Jun 2010, 08:13 AM
Hello cmr,

The current implementation of the PaletteBrushes property applies the colors to the series in the order they come from the items source. You should sync this order manually in order to be sure that every time a visual series will get the correct brush applied. 

Regards,
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
Tags
Chart
Asked by
MacKenzie Mickelsen
Top achievements
Rank 1
Answers by
Velin
Telerik team
Denny
Top achievements
Rank 1
Odd Veibust
Top achievements
Rank 1
cmr
Top achievements
Rank 1
Share this question
or