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

How to set colors dinamically for individual slices?

2 Answers 69 Views
Chart (obsolete as of Q1 2013)
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
gmendez
Top achievements
Rank 1
gmendez asked on 27 Mar 2009, 06:16 PM
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 Answers, 1 is accepted

Sort by
0
Accepted
Dwight
Telerik team
answered on 30 Mar 2009, 07:55 AM
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.
0
gmendez
Top achievements
Rank 1
answered on 01 Apr 2009, 02:37 PM
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
Tags
Chart (obsolete as of Q1 2013)
Asked by
gmendez
Top achievements
Rank 1
Answers by
Dwight
Telerik team
gmendez
Top achievements
Rank 1
Share this question
or