Getting a series colour after a palette has been set

7 posts, 1 answers
  1. Kareema
    Kareema avatar
    17 posts
    Member since:
    Aug 2011

    Posted 09 Jul 2012 Link to this post

    After dynamically applying a palette to a chart, how do I find the color of a particular series on that chart based on the palette application?

    My xaml is as follows:
    <Controls:RadCartesianChart x:Name="chart" Palette="{Binding SelectedPalette, Mode=TwoWay}" >

    If the value of  SelectedPalette changes, I want to know the resulting color of any given Series in the chart's  SeriesCollection in my xaml.cs. The types of these charts may be BarSeries, LineSeries or AreaSeries .

    Thanks
  2. Answer
    Yavor
    Admin
    Yavor avatar
    401 posts

    Posted 12 Jul 2012 Link to this post

    Hi Kareema,

    The chart series get their brushes from the GlobalEntries array. You can get the color for the series by using the index of the series like this:
    int seriesIndex = chart.Series.IndexOf(series);
    return chart.Palette.GlobalEntries[seriesIndex].Fill;

    Hope this information helps!

    Greetings,
    Yavor
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  3. UI for WPF is Visual Studio 2017 Ready
  4. Kareema
    Kareema avatar
    17 posts
    Member since:
    Aug 2011

    Posted 12 Jul 2012 Link to this post

    Thank you very much Yavor!

    I found that this works too:

    PaletteEntry? paletteEntryForThisSeries = chart.Palette.GetEntry(series, seriesCounter);
                        if (paletteEntryForThisSeries.HasValue)
                        {
                            var paletteFill = paletteEntryForThisSeries.Value.Fill;
                        }
  5. Greg
    Greg avatar
    29 posts
    Member since:
    Oct 2007

    Posted 13 Feb 2013 Link to this post

    This only works with up to 8 series on the chart, then fails with an "index out of range" exception. How can I determine the color of all series beyond 8 in the chart?
  6. Petar Marchev
    Admin
    Petar Marchev avatar
    968 posts

    Posted 19 Feb 2013 Link to this post

    Hi Greg,

    I have just verified that using the GetEntry method of the ChartPalette does not throw an exception in the described scenario. If you keep experiencing problems with this I will ask that you provide us with a small working example that reproduces this issue so that we can test and look for solutions.

    Kind regards,
    Petar Marchev
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  7. Bruno
    Bruno avatar
    3 posts
    Member since:
    Jul 2015

    Posted 08 Jul 2015 Link to this post

    Hello, I'm trying to do a similar thing, but instead of getting this color from code-behind, I need to bind to it from xaml. I've bound my series using a ChartSeriesProvider, and I'd like to display other informations on these series on another control, reusing the color that's chosen by the palette. How would I do that ?
  8. Petar Marchev
    Admin
    Petar Marchev avatar
    968 posts

    Posted 13 Jul 2015 Link to this post

    Hello Bruno,

    You can either use a converter and use code to get the desired color or you can use the legend item and its Fill property. If you need further assistance I will ask that you open a new thread where you can explain in more details the set up you have and the desired output.

    Regards,
    Petar Marchev
    Telerik
    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 Feedback Portal and vote to affect the priority of the items
Back to Top
UI for WPF is Visual Studio 2017 Ready