Getting color series

3 posts, 0 answers
  1. david
    david avatar
    4 posts
    Member since:
    Jan 2013

    Posted 29 Aug 2013 Link to this post


    I have a radchart and personalized chartlegend. In my chartlegend I have a checkbox and I need to get the color that has given radchart sets. But when I try to know the color, in "aparrence" fields appear all to null, but really if you are painting with a certain color.

    <telerik:RadChart x:Name="RadChart1"
            <telerik:SamplingSettings SamplingFunction="Average" />
                <ColumnDefinition Width="10" />
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="10" />
                <RowDefinition Height="10" />
                <RowDefinition Height="*" />
                <RowDefinition Height="100" />
                <RowDefinition Height="10" />
            <Grid />
            <telerik:ChartLegend x:Name="legendChart"
                                 ItemContainerStyle="{DynamicResource CharLegendStyle}"
                                 UseAutoGeneratedItems="false" />
            <telerik:ChartArea x:Name="lineGraphChartArea"
                    <telerik:AxisX Title="Fecha"
                                   Step="1" />
                    <telerik:AxisY Title="CMN"
                                   IsZeroBased="True" />

    public SeriesMapping GenerateRandomSeries(string nameSerie,int begin)
                SeriesMapping serie1 = new SeriesMapping();
                serie1.ItemsSource = GenerateRandomData(begin);
                serie1.ChartAreaName = "lineGraphChartArea";
                serie1.LegendLabel = nameSerie;
                ItemMapping X = new ItemMapping("Fecha", DataPointMember.XValue);
                ItemMapping Y = new ItemMapping("CMN", DataPointMember.YValue);
                serie1.SeriesDefinition = new SplineSeriesDefinition()
                return serie1;
    public void AddSerieDefinition()

    I try get color and (look attached)

    Thank you!
  2. Evgenia
    Evgenia avatar
    1437 posts

    Posted 03 Sep 2013 Link to this post

    Hi David,

      Unfortunately, there is no easy way to extract the colors of the visual series and use it to manually generate legend items. There are two workarounds though that you may choose from:
    1. 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);

    2. You might create your own custom Palette and apply it to the Chart as shown in our documentation. When the underlying data is changed, you can add/remove/alter the palette brushes accordingly, in order to preserve the logical correlation between some serie and its corresponding Color. Check this online example with source code provided where you will see how we keep the relation between a color and series because when a series is not visible (the corresponding checkbox is unchecked), it is actually hidden. Please mind that even though the example is made under Silverlight, the code is practically the same for WPF.

    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  3. david
    david avatar
    4 posts
    Member since:
    Jan 2013

    Posted 03 Sep 2013 Link to this post

    Thank you!!
Back to Top