How to set colors dinamically for individual slices?

3 posts, 1 answers
  1. gmendez
    gmendez avatar
    82 posts
    Member since:
    Jun 2012

    Posted 27 Mar 2009 Link to this post

    Hello,

    I'm working (for the first time) with a RadChart (pie).
    I'm binding it to a IBindingList<MyClass>. MyClass defines 2 properties, one for the legend and the other is for the percentage.
    Id like to set the color for individual slices depending on the item object they are representing. I would distinguish them using the property wich contains the legend (It's called "Name").
    Is it possible? I'm trying this, which is not working:

    (after Data Binding)

                grafica1.Series[0].Items[0].Appearance.FillStyle.MainColor = Color.LightGreen;
                grafica1.Series[0].Items[1].Appearance.FillStyle.MainColor = Color.Yellow;
                grafica1.Series[0].Items[2].Appearance.FillStyle.MainColor = Color.Red;
                grafica1.UpdateGraphics();

    and also this:

            private void grafica1_ItemDataBound(object sender, Telerik.Charting.ChartItemDataBoundEventArgs e)
            {
                if (e.SeriesItem != null)
                {
                    DataRowView percentage = e.DataItem as DataRowView;
                    if (percentage != null)
                    {
                        if (percentage["Name"] == "Apto")
                            e.SeriesItem.Appearance.FillStyle.MainColor = Color.LightGreen;
                        else if (percentage["Name"] == "Móvil")
                            e.SeriesItem.Appearance.FillStyle.MainColor = Color.Yellow;
                        else
                            e.SeriesItem.Appearance.FillStyle.MainColor = Color.Red;
                        grafica1.UpdateGraphics();

                        
                        e.SeriesItem.Label.TextBlock.Text = string.Format("{0} %", percentage["Cantidad"]);
                    }
                }
            }

    None of these aproaches is working :(
    Best regards,

    Gonzalo
  2. Answer
    Dwight
    Admin
    Dwight avatar
    475 posts

    Posted 30 Mar 2009 Link to this post

    Hi gonzalo,

    Both approaches should be working fine. Please, try setting the ChartSeriesItems' FillType:
    radChart1.Series[0].Items[0].Appearance.FillStyle.FillType = FillType.Solid;
    or
    e.SeriesItem.Appearance.FillStyle.FillType = FillType.Solid;

    If you still have problems setting the color, please, send a simple project that we can analyze.

    Kind regards,
    Evtim
    the Telerik team

    Check out Telerik Trainer , the state of the art learning tool for Telerik products.
  3. UI for WinForms is Visual Studio 2017 Ready
  4. gmendez
    gmendez avatar
    82 posts
    Member since:
    Jun 2012

    Posted 01 Apr 2009 Link to this post

    Hi Evtim,

    The clues you gave me in your reply helped me in achieving some effects I was looking for.
    But the real problem was that I had missunderstood a post in this forum about colors in RadChard and I had done this:

    grafica1.SkinsOverrideStyles = true;

    I tryed setting the RadChart.SkinsOverrideStyles property to false and then It worked ok.

    Thanks a lot.

    Gonzalo
Back to Top