RadChart - PIE - Assign pie segments indivdual colors

Thread is closed for posting
4 posts, 0 answers
  1. Karl
    Karl avatar
    172 posts
    Member since:
    Jun 2009

    Posted 01 Aug 2013 Link to this post

    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;
     
                }
                 
            }
        }
  2. A2H
    A2H avatar
    177 posts
    Member since:
    Mar 2010

    Posted 01 Aug 2013 Link to this post

    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
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Karl
    Karl avatar
    172 posts
    Member since:
    Jun 2009

    Posted 01 Aug 2013 Link to this post

    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;
     
                }
                 
            }
        }
  5. Saroop
    Saroop avatar
    5 posts
    Member since:
    Aug 2013

    Posted 28 Aug 2013 Link to this post

    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;
     
                }
                 
            }
        }
Back to Top