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

RadChart - PIE - Assign pie segments indivdual colors

3 Answers 59 Views
Chart (Obsolete)
This is a migrated thread and some comments may be shown as answers.
Karl
Top achievements
Rank 1
Karl asked on 01 Aug 2013, 12:30 PM
Hi,

I have a pie chart where I am trying to assign a color based on the series data item being returned from a stored procedure. However, no matter what I seem to do it always appears to maintain a gradient in the pie segment as well as coloring it RED.

What am I doing wrong? I have also set SkinsOverrideStyles="false"
protected void rcOrderTotalStages_ItemDataBound(object sender, ChartItemDataBoundEventArgs e)
    {
        //bind the legend to the report type title name from SQL data source
        e.SeriesItem.Name = (string)DataBinder.Eval(e.DataItem, "report_type_title") + " (" + (Int32)DataBinder.Eval(e.DataItem, "report_type_count") + ")";
        e.ChartSeries.Appearance.ShowLabelConnectors = true;
        
        e.SeriesItem.ActiveRegion.Tooltip =  (string)DataBinder.Eval(e.DataItem, "report_type_desc") + " (" + (Int32)DataBinder.Eval(e.DataItem, "report_type_count") + ")";
   
        //for each of the chart series set the exploded property to true and bind a colour to the pie segment depending on status/report_type-title
        int ChartSeriesItemCount = e.ChartSeries.Items.Count;
        for (int i = 0; i < ChartSeriesItemCount; i++)
        {
            e.ChartSeries.Items[i].Appearance.Exploded = true;
            string status = "";
            status = (string)DataBinder.Eval(e.DataItem, "report_type_title");
          
            switch (status)
            {                   
                case "Delivered":
                    e.ChartSeries.Items[i].Appearance.FillStyle.FillType = Telerik.Charting.Styles.FillType.Solid;
                    e.ChartSeries.Items[i].Appearance.FillStyle.MainColor = System.Drawing.Color.Green;                   
                    break;
                case "Bill & Hold":
                    e.ChartSeries.Items[i].Appearance.FillStyle.FillType = Telerik.Charting.Styles.FillType.Solid;
                    e.ChartSeries.Items[i].Appearance.FillStyle.MainColor = System.Drawing.Color.Green;                   
                    break;
                case "Prep Complete":
                    e.ChartSeries.Items[i].Appearance.FillStyle.MainColor = System.Drawing.Color.Green;
                    break;
                case "In Prep":
                    e.ChartSeries.Items[i].Appearance.FillStyle.MainColor = System.Drawing.Color.Orange;
                    break;
                case "Sent To Schedule":
                    e.ChartSeries.Items[i].Appearance.FillStyle.MainColor = System.Drawing.Color.Orange;
                    break;
                case "On Order/Ghost Slot":
                    e.ChartSeries.Items[i].Appearance.FillStyle.MainColor = System.Drawing.Color.Orange;
                    break;
                case "On Order":
                    e.ChartSeries.Items[i].Appearance.FillStyle.MainColor = System.Drawing.Color.Red;
                    break;
                case "Stock":
                    e.ChartSeries.Items[i].Appearance.FillStyle.MainColor = System.Drawing.Color.Red;
                    break;
                case "Not On Stock":
                    e.ChartSeries.Items[i].Appearance.FillStyle.MainColor = System.Drawing.Color.Red;
                    break;
                case "Cancelled":
                    e.ChartSeries.Items[i].Appearance.FillStyle.MainColor = System.Drawing.Color.Blue;
                    break;
                case "Status Unknown":
                    e.ChartSeries.Items[i].Appearance.FillStyle.MainColor = System.Drawing.Color.Gray;
                    break;
                default:
                    e.ChartSeries.Items[i].Appearance.FillStyle.MainColor = System.Drawing.Color.Yellow;
                    break;
 
            }
             
        }
    }

3 Answers, 1 is accepted

Sort by
0
A2H
Top achievements
Rank 1
answered on 01 Aug 2013, 02:13 PM
Hello,

I believe you want to apply solid coloring for pie chart segments,if that is the case 

Please modify you code like given below
protected void rcOrderTotalStages_ItemDataBound(object sender, ChartItemDataBoundEventArgs e)
    {
        //bind the legend to the report type title name from SQL data source
        e.SeriesItem.Name = (string)DataBinder.Eval(e.DataItem, "report_type_title") + " (" + (Int32)DataBinder.Eval(e.DataItem, "report_type_count") + ")";
        e.ChartSeries.Appearance.ShowLabelConnectors = true;
 
        e.SeriesItem.ActiveRegion.Tooltip = (string)DataBinder.Eval(e.DataItem, "report_type_desc") + " (" + (Int32)DataBinder.Eval(e.DataItem, "report_type_count") + ")";
 
        //for each of the chart series set the exploded property to true and bind a colour to the pie segment depending on status/report_type-title
        int ChartSeriesItemCount = e.ChartSeries.Items.Count;
        for (int i = 0; i < ChartSeriesItemCount; i++)
        {
            e.ChartSeries.Items[i].Appearance.Exploded = true;
            string status = "";
            status = (string)DataBinder.Eval(e.DataItem, "report_type_title");
 
            switch (status)
            {
                case "Delivered":
                    //e.ChartSeries.Items[i].Appearance.FillStyle.FillType = Telerik.Charting.Styles.FillType.Solid;
                    e.ChartSeries.Items[i].Appearance.FillStyle.FillType = Telerik.Charting.Styles.FillType.Gradient;
                    e.ChartSeries.Items[i].Appearance.FillStyle.MainColor = System.Drawing.Color.Green;
                    e.ChartSeries.Items[i].Appearance.FillStyle.SecondColor = System.Drawing.Color.Green;
                    break;
                case "Bill & Hold":
                    //e.ChartSeries.Items[i].Appearance.FillStyle.FillType = Telerik.Charting.Styles.FillType.Solid;
                     e.ChartSeries.Items[i].Appearance.FillStyle.FillType = Telerik.Charting.Styles.FillType.Gradient;
                    e.ChartSeries.Items[i].Appearance.FillStyle.MainColor = System.Drawing.Color.Green;
                    e.ChartSeries.Items[i].Appearance.FillStyle.SecondColor = System.Drawing.Color.Green;
                    break;
                case "Prep Complete":
                    e.ChartSeries.Items[i].Appearance.FillStyle.MainColor = System.Drawing.Color.Green;
                    break;
                case "In Prep":
                    e.ChartSeries.Items[i].Appearance.FillStyle.MainColor = System.Drawing.Color.Orange;
                    break;
                case "Sent To Schedule":
                    e.ChartSeries.Items[i].Appearance.FillStyle.MainColor = System.Drawing.Color.Orange;
                    break;
                case "On Order/Ghost Slot":
                    e.ChartSeries.Items[i].Appearance.FillStyle.MainColor = System.Drawing.Color.Orange;
                    break;
                case "On Order":
                    e.ChartSeries.Items[i].Appearance.FillStyle.MainColor = System.Drawing.Color.Red;
                    break;
                case "Stock":
                    e.ChartSeries.Items[i].Appearance.FillStyle.MainColor = System.Drawing.Color.Red;
                    break;
                case "Not On Stock":
                    e.ChartSeries.Items[i].Appearance.FillStyle.MainColor = System.Drawing.Color.Red;
                    break;
                case "Cancelled":
                    e.ChartSeries.Items[i].Appearance.FillStyle.MainColor = System.Drawing.Color.Blue;
                    break;
                case "Status Unknown":
                    e.ChartSeries.Items[i].Appearance.FillStyle.MainColor = System.Drawing.Color.Gray;
                    break;
                default:
                    e.ChartSeries.Items[i].Appearance.FillStyle.MainColor = System.Drawing.Color.Yellow;
                    break;
 
            }
 
        }
    }

Thanks,
A2H
0
Karl
Top achievements
Rank 1
answered on 01 Aug 2013, 04:01 PM

Thanks for the response.

I have tried what you suggested but all the pie segments now just turn red.

protected void rcOrderTotalStages_ItemDataBound(object sender, ChartItemDataBoundEventArgs e)
    {
        //bind the legend to the report type title name from SQL data source
        e.SeriesItem.Name = (string)DataBinder.Eval(e.DataItem, "report_type_title") + " (" + (Int32)DataBinder.Eval(e.DataItem, "report_type_count") + ")";
        e.ChartSeries.Appearance.ShowLabelConnectors = true;
        
        e.SeriesItem.ActiveRegion.Tooltip =  (string)DataBinder.Eval(e.DataItem, "report_type_desc") + " (" + (Int32)DataBinder.Eval(e.DataItem, "report_type_count") + ")";
   
        //for each of the chart series set the exploded property to true and bind a colour to the pie segment depending on status/report_type-title
        int ChartSeriesItemCount = e.ChartSeries.Items.Count;
        for (int i = 0; i < ChartSeriesItemCount; i++)
        {
            e.ChartSeries.Items[i].Appearance.Exploded = true;
            string status = "";
            status = (string)DataBinder.Eval(e.DataItem, "report_type_title");
          
            switch (status)
            {                   
                case "Delivered":
                    e.ChartSeries.Items[i].Appearance.FillStyle.FillType = Telerik.Charting.Styles.FillType.Gradient;
                    e.ChartSeries.Items[i].Appearance.FillStyle.MainColor = System.Drawing.Color.Green;
                    e.ChartSeries.Items[i].Appearance.FillStyle.SecondColor = System.Drawing.Color.Green;                
                    break;
                case "Bill & Hold":
                    e.ChartSeries.Items[i].Appearance.FillStyle.FillType = Telerik.Charting.Styles.FillType.Gradient;
                    e.ChartSeries.Items[i].Appearance.FillStyle.MainColor = System.Drawing.Color.Green;
                    e.ChartSeries.Items[i].Appearance.FillStyle.SecondColor = System.Drawing.Color.Green;                  
                    break;
                case "Prep Complete":
                    e.ChartSeries.Items[i].Appearance.FillStyle.FillType = Telerik.Charting.Styles.FillType.Gradient;
                    e.ChartSeries.Items[i].Appearance.FillStyle.MainColor = System.Drawing.Color.Green;
                    e.ChartSeries.Items[i].Appearance.FillStyle.SecondColor = System.Drawing.Color.Green;
                    break;
                case "In Prep":
                    e.ChartSeries.Items[i].Appearance.FillStyle.FillType = Telerik.Charting.Styles.FillType.Gradient;
                    e.ChartSeries.Items[i].Appearance.FillStyle.MainColor = System.Drawing.Color.Orange;
                    e.ChartSeries.Items[i].Appearance.FillStyle.SecondColor = System.Drawing.Color.Orange;
                    break;
                case "Sent To Schedule":
                     e.ChartSeries.Items[i].Appearance.FillStyle.FillType = Telerik.Charting.Styles.FillType.Gradient;
                    e.ChartSeries.Items[i].Appearance.FillStyle.MainColor = System.Drawing.Color.Orange;
                    e.ChartSeries.Items[i].Appearance.FillStyle.SecondColor = System.Drawing.Color.Orange;
                    break;
                case "On Order/Ghost Slot":
                      e.ChartSeries.Items[i].Appearance.FillStyle.FillType = Telerik.Charting.Styles.FillType.Gradient;
                    e.ChartSeries.Items[i].Appearance.FillStyle.MainColor = System.Drawing.Color.Orange;
                    e.ChartSeries.Items[i].Appearance.FillStyle.SecondColor = System.Drawing.Color.Orange;
                    break;
                case "On Order":
                      e.ChartSeries.Items[i].Appearance.FillStyle.FillType = Telerik.Charting.Styles.FillType.Gradient;
                    e.ChartSeries.Items[i].Appearance.FillStyle.MainColor = System.Drawing.Color.Red;
                    e.ChartSeries.Items[i].Appearance.FillStyle.SecondColor = System.Drawing.Color.Red;
                    break;
                case "Stock":
                    e.ChartSeries.Items[i].Appearance.FillStyle.FillType = Telerik.Charting.Styles.FillType.Gradient;
                    e.ChartSeries.Items[i].Appearance.FillStyle.MainColor = System.Drawing.Color.Red;
                    e.ChartSeries.Items[i].Appearance.FillStyle.SecondColor = System.Drawing.Color.Red;
                    break;
                case "Not On Stock":
                    e.ChartSeries.Items[i].Appearance.FillStyle.FillType = Telerik.Charting.Styles.FillType.Gradient;
                    e.ChartSeries.Items[i].Appearance.FillStyle.MainColor = System.Drawing.Color.Red;
                    e.ChartSeries.Items[i].Appearance.FillStyle.SecondColor = System.Drawing.Color.Red;
                    break;
                case "Cancelled":
                    e.ChartSeries.Items[i].Appearance.FillStyle.FillType = Telerik.Charting.Styles.FillType.Gradient;
                    e.ChartSeries.Items[i].Appearance.FillStyle.MainColor = System.Drawing.Color.Blue;
                    e.ChartSeries.Items[i].Appearance.FillStyle.SecondColor = System.Drawing.Color.Blue;
                    break;
                case "Status Unknown":
                    e.ChartSeries.Items[i].Appearance.FillStyle.FillType = Telerik.Charting.Styles.FillType.Gradient;
                    e.ChartSeries.Items[i].Appearance.FillStyle.MainColor = System.Drawing.Color.Gray;
                    e.ChartSeries.Items[i].Appearance.FillStyle.SecondColor = System.Drawing.Color.Gray;
                    break;
                default:
                    e.ChartSeries.Items[i].Appearance.FillStyle.MainColor = System.Drawing.Color.Yellow;
                    break;
 
            }
             
        }
    }
0
Saroop
Top achievements
Rank 1
answered on 28 Aug 2013, 07:32 AM
This requires little change, try the below

protected void rcOrderTotalStages_ItemDataBound(object sender, ChartItemDataBoundEventArgs e)
    {
        //bind the legend to the report type title name from SQL data source
        e.SeriesItem.Name = (string)DataBinder.Eval(e.DataItem, "report_type_title"); // + " (" + (Int32)DataBinder.Eval(e.DataItem, "report_type_count") + ")";
        e.ChartSeries.Appearance.ShowLabelConnectors = true;
        
        e.SeriesItem.ActiveRegion.Tooltip =  (string)DataBinder.Eval(e.DataItem, "report_type_desc") + " (" + (Int32)DataBinder.Eval(e.DataItem, "report_type_count") + ")";
   
        //for each of the chart series set the exploded property to true and bind a colour to the pie segment depending on status/report_type-title
        int ChartSeriesItemCount = e.ChartSeries.Items.Count;
        for (int i = 0; i < ChartSeriesItemCount; i++)
        {
            e.ChartSeries.Items[i].Appearance.Exploded = true;
            string status = "";
            //status = (string)DataBinder.Eval(e.DataItem, "report_type_title");
status = e.ChartSeries.Items[i].Name.ToString();
          
            switch (status)
            {                   
                case "Delivered":
                    e.ChartSeries.Items[i].Appearance.FillStyle.FillType = Telerik.Charting.Styles.FillType.Gradient;
                    e.ChartSeries.Items[i].Appearance.FillStyle.MainColor = System.Drawing.Color.Green;
                    e.ChartSeries.Items[i].Appearance.FillStyle.SecondColor = System.Drawing.Color.Green;                
                    break;
                case "Bill & Hold":
                    e.ChartSeries.Items[i].Appearance.FillStyle.FillType = Telerik.Charting.Styles.FillType.Gradient;
                    e.ChartSeries.Items[i].Appearance.FillStyle.MainColor = System.Drawing.Color.Green;
                    e.ChartSeries.Items[i].Appearance.FillStyle.SecondColor = System.Drawing.Color.Green;                  
                    break;
                case "Prep Complete":
                    e.ChartSeries.Items[i].Appearance.FillStyle.FillType = Telerik.Charting.Styles.FillType.Gradient;
                    e.ChartSeries.Items[i].Appearance.FillStyle.MainColor = System.Drawing.Color.Green;
                    e.ChartSeries.Items[i].Appearance.FillStyle.SecondColor = System.Drawing.Color.Green;
                    break;
                case "In Prep":
                    e.ChartSeries.Items[i].Appearance.FillStyle.FillType = Telerik.Charting.Styles.FillType.Gradient;
                    e.ChartSeries.Items[i].Appearance.FillStyle.MainColor = System.Drawing.Color.Orange;
                    e.ChartSeries.Items[i].Appearance.FillStyle.SecondColor = System.Drawing.Color.Orange;
                    break;
                case "Sent To Schedule":
                     e.ChartSeries.Items[i].Appearance.FillStyle.FillType = Telerik.Charting.Styles.FillType.Gradient;
                    e.ChartSeries.Items[i].Appearance.FillStyle.MainColor = System.Drawing.Color.Orange;
                    e.ChartSeries.Items[i].Appearance.FillStyle.SecondColor = System.Drawing.Color.Orange;
                    break;
                case "On Order/Ghost Slot":
                      e.ChartSeries.Items[i].Appearance.FillStyle.FillType = Telerik.Charting.Styles.FillType.Gradient;
                    e.ChartSeries.Items[i].Appearance.FillStyle.MainColor = System.Drawing.Color.Orange;
                    e.ChartSeries.Items[i].Appearance.FillStyle.SecondColor = System.Drawing.Color.Orange;
                    break;
                case "On Order":
                      e.ChartSeries.Items[i].Appearance.FillStyle.FillType = Telerik.Charting.Styles.FillType.Gradient;
                    e.ChartSeries.Items[i].Appearance.FillStyle.MainColor = System.Drawing.Color.Red;
                    e.ChartSeries.Items[i].Appearance.FillStyle.SecondColor = System.Drawing.Color.Red;
                    break;
                case "Stock":
                    e.ChartSeries.Items[i].Appearance.FillStyle.FillType = Telerik.Charting.Styles.FillType.Gradient;
                    e.ChartSeries.Items[i].Appearance.FillStyle.MainColor = System.Drawing.Color.Red;
                    e.ChartSeries.Items[i].Appearance.FillStyle.SecondColor = System.Drawing.Color.Red;
                    break;
                case "Not On Stock":
                    e.ChartSeries.Items[i].Appearance.FillStyle.FillType = Telerik.Charting.Styles.FillType.Gradient;
                    e.ChartSeries.Items[i].Appearance.FillStyle.MainColor = System.Drawing.Color.Red;
                    e.ChartSeries.Items[i].Appearance.FillStyle.SecondColor = System.Drawing.Color.Red;
                    break;
                case "Cancelled":
                    e.ChartSeries.Items[i].Appearance.FillStyle.FillType = Telerik.Charting.Styles.FillType.Gradient;
                    e.ChartSeries.Items[i].Appearance.FillStyle.MainColor = System.Drawing.Color.Blue;
                    e.ChartSeries.Items[i].Appearance.FillStyle.SecondColor = System.Drawing.Color.Blue;
                    break;
                case "Status Unknown":
                    e.ChartSeries.Items[i].Appearance.FillStyle.FillType = Telerik.Charting.Styles.FillType.Gradient;
                    e.ChartSeries.Items[i].Appearance.FillStyle.MainColor = System.Drawing.Color.Gray;
                    e.ChartSeries.Items[i].Appearance.FillStyle.SecondColor = System.Drawing.Color.Gray;
                    break;
                default:
                    e.ChartSeries.Items[i].Appearance.FillStyle.MainColor = System.Drawing.Color.Yellow;
                    break;
 
            }
             
        }
    }
Tags
Chart (Obsolete)
Asked by
Karl
Top achievements
Rank 1
Answers by
A2H
Top achievements
Rank 1
Karl
Top achievements
Rank 1
Saroop
Top achievements
Rank 1
Share this question
or