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

Items coloring problem

3 Answers 141 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Bader
Top achievements
Rank 1
Bader asked on 09 Aug 2011, 02:06 PM
Hi,

I'm trying to color the series items in the Pie chart, but I failed.
Here is my code:

//Pie chart Item Data Binding
        private void pieChart_ItemDataBinding_1(object sender, EventArgs e)
        {
            Telerik.Reporting.Processing.Chart chart = sender as Telerik.Reporting.Processing.Chart;
            Telerik.Reporting.Processing.DetailSection section = (Telerik.Reporting.Processing.DetailSection)chart.Parent;
            Telerik.Reporting.Processing.IDataObject dataObject = (Telerik.Reporting.Processing.IDataObject)section.DataObject;
            object rowdata = (object)section.DataObject.RawData;
            Telerik.Reporting.Processing.TextBox procTextbox = (Telerik.Reporting.Processing.TextBox)section.ChildElements.Find("taskIDTextBox", true)[0];
  
            Telerik.Reporting.Chart chartDef = (Telerik.Reporting.Chart)chart.ItemDefinition;
            Telerik.Reporting.Charting.ChartSeries series = new Telerik.Reporting.Charting.ChartSeries();
            series.Type = ChartSeriesType.Pie;
            Telerik.Reporting.Charting.ChartLegend legend = new Telerik.Reporting.Charting.ChartLegend();
  
            string CoverDescription;
            int itemValue;
  
            string commandText = string.Empty;
            SqlConnection connection = new SqlConnection(global::QTaskReporting.Properties.Settings.Default.QTDbConnString);
            commandText = "SELECT COUNT(*) AS ItemCount, SDesc, SColor FROM vwSubTasksAndStatuses where TaskID = " + procTextbox.Value + " GROUP BY SDesc,SColor";
            SqlCommand cmd = new SqlCommand(commandText, connection);
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataSet ds = new DataSet();
            da.Fill(ds);
  
            foreach (DataRow rowView in ds.Tables[0].Rows)
            {
                Telerik.Reporting.Charting.ChartSeriesItem seriesItem = new Telerik.Reporting.Charting.ChartSeriesItem();
  
                //The chart Y value will be based on the Value amount 
                seriesItem.YValue = Convert.ToInt32(rowView["ItemCount"]);
                seriesItem.Appearance.FillStyle.FillType = Telerik.Reporting.Charting.Styles.FillType.Solid;
  
                //The chart item label should be set to the Value amount 
                itemValue = Convert.ToInt32(rowView["ItemCount"]);
                seriesItem.Label.TextBlock.Text = rowView["SColor"].ToString().Trim() + " - " + rowView["SDesc"].ToString();
                seriesItem.Label.Appearance.LabelLocation = Telerik.Reporting.Charting.Styles.StyleSeriesItemLabel.ItemLabelLocation.Inside;
                seriesItem.Label.TextBlock.Appearance.TextProperties.Color = System.Drawing.Color.FromArgb(((int)(((byte)(28)))), ((int)(((byte)(58)))), ((int)(((byte)(112)))));
                seriesItem.Appearance.FillStyle.FillType = Telerik.Reporting.Charting.Styles.FillType.Solid;
                seriesItem.Appearance.FillStyle.MainColor = ColorTranslator.FromHtml("#" + rowView["SColor"].ToString().Trim());
  
                //Assign the chart item description
                CoverDescription = rowView["SDesc"].ToString();
                seriesItem.Name = CoverDescription.Trim();
  
                //Give the "New" chart item an exploded appearance
                if (seriesItem.Name == "New")
                {
                    seriesItem.Appearance.Exploded = true;
                }
  
                series.AddItem(seriesItem);
  
            }
  
            //Display the legend
            series.Appearance.LegendDisplayMode = ChartSeriesLegendDisplayMode.ItemLabels;
            series.Appearance.Border.Color = System.Drawing.Color.White;
            series.Appearance.Border.Visible = false;
            series.Appearance.DiameterScale = .90;
  
            series.Appearance.ExplodePercent = 10;
  
            chartDef.Series.Clear();
            chartDef.Series.Add(series);
  
            chartDef.Legend.Appearance.Position.AlignedPosition = Telerik.Reporting.Charting.Styles.AlignedPositions.TopRight;
        }

View attached screen-shots in order to show you that the Pie chart doesn't display the colors I sat for the items.
By the way the pie chart displays the real data, but the colors are wrong.

Please, I need your help in order to solve the above problem.
It is appreciated to send me the modified code.

Regards,
Bader

3 Answers, 1 is accepted

Sort by
0
Steve
Telerik team
answered on 10 Aug 2011, 01:48 PM
Hi Bader,

The code you've pasted looks correct and works correctly on our end. The only difference we notice is that you're using the ItemDataBinding event, when the correct event should be NeedDataSource. Additionally, the chart item should not have DataSource or Skin set in the Report Designer - if set, please remove them.

Regards,
Steve
the Telerik team

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

0
Bader
Top achievements
Rank 1
answered on 14 Aug 2011, 12:15 PM
Hello,

Thank you for your reply,
Moving the code to the NeedDataSource method doesn't solve the problem.
I don't know, the problem could be as a result of the Designer.cs file code:
// 
            // pieChart
            // 
            this.pieChart.Appearance.Border.Color = System.Drawing.Color.FromArgb(((int)(((byte)(188)))), ((int)(((byte)(229)))), ((int)(((byte)(231)))));
            this.pieChart.Appearance.Border.Visible = false;
            this.pieChart.Appearance.Border.Width = 8F;
            this.pieChart.AutoTextWrap = true;
            this.pieChart.BitmapResolution = 96F;
            chartMarginsTitle1.Bottom = new Telerik.Reporting.Charting.Styles.Unit(10D, Telerik.Reporting.Charting.Styles.UnitType.Pixel);
            chartMarginsTitle1.Left = new Telerik.Reporting.Charting.Styles.Unit(7D, Telerik.Reporting.Charting.Styles.UnitType.Percentage);
            chartMarginsTitle1.Right = new Telerik.Reporting.Charting.Styles.Unit(10D, Telerik.Reporting.Charting.Styles.UnitType.Pixel);
            chartMarginsTitle1.Top = new Telerik.Reporting.Charting.Styles.Unit(4D, Telerik.Reporting.Charting.Styles.UnitType.Percentage);
            this.pieChart.ChartTitle.Appearance.Dimensions.Margins = chartMarginsTitle1;
            this.pieChart.ChartTitle.Appearance.FillStyle.MainColor = System.Drawing.Color.Empty;
            this.pieChart.ChartTitle.TextBlock.Appearance.TextProperties.Color = System.Drawing.Color.FromArgb(((int)(((byte)(232)))), ((int)(((byte)(140)))), ((int)(((byte)(0)))));
            this.pieChart.ChartTitle.TextBlock.Appearance.TextProperties.Font = new System.Drawing.Font("Verdana", 20F, System.Drawing.FontStyle.Bold);
            this.pieChart.ChartTitle.TextBlock.Visible = false;
            paletteItem1.MainColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(0)))), ((int)(((byte)(0)))));
            paletteItem1.SecondColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(166)))), ((int)(((byte)(78)))));
            paletteItem2.MainColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(255)))), ((int)(((byte)(0)))));
            paletteItem2.SecondColor = System.Drawing.Color.FromArgb(((int)(((byte)(125)))), ((int)(((byte)(211)))), ((int)(((byte)(241)))));
            paletteItem3.MainColor = System.Drawing.Color.FromArgb(((int)(((byte)(192)))), ((int)(((byte)(192)))), ((int)(((byte)(192)))));
            paletteItem3.SecondColor = System.Drawing.Color.FromArgb(((int)(((byte)(172)))), ((int)(((byte)(219)))), ((int)(((byte)(74)))));
            paletteItem4.MainColor = System.Drawing.Color.FromArgb(((int)(((byte)(224)))), ((int)(((byte)(86)))), ((int)(((byte)(182)))));
            paletteItem4.SecondColor = System.Drawing.Color.FromArgb(((int)(((byte)(246)))), ((int)(((byte)(143)))), ((int)(((byte)(217)))));
            paletteItem5.MainColor = System.Drawing.Color.FromArgb(((int)(((byte)(239)))), ((int)(((byte)(185)))), ((int)(((byte)(39)))));
            paletteItem5.Name = "PaletteItem 1";
            paletteItem5.SecondColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(223)))), ((int)(((byte)(74)))));
            palette1.Items.AddRange(new Telerik.Reporting.Charting.PaletteItem[] {
            paletteItem1,
            paletteItem2,
            paletteItem3,
            paletteItem4,
            paletteItem5});
            palette1.Name = "Palette1";
            this.pieChart.CustomPalettes.AddRange(new Telerik.Reporting.Charting.Palette[] {
            palette1});
            this.pieChart.DefaultType = Telerik.Reporting.Charting.ChartSeriesType.Pie;
            this.pieChart.ImageFormat = System.Drawing.Imaging.ImageFormat.Emf;
            this.pieChart.IntelligentLabelsEnabled = true;
            this.pieChart.Legend.Appearance.Border.Color = System.Drawing.Color.FromArgb(((int)(((byte)(194)))), ((int)(((byte)(212)))), ((int)(((byte)(109)))));
            corners1.BottomLeft = Telerik.Reporting.Charting.Styles.CornerType.Round;
            corners1.BottomRight = Telerik.Reporting.Charting.Styles.CornerType.Round;
            corners1.RoundSize = 6;
            corners1.TopLeft = Telerik.Reporting.Charting.Styles.CornerType.Round;
            corners1.TopRight = Telerik.Reporting.Charting.Styles.CornerType.Round;
            this.pieChart.Legend.Appearance.Corners = corners1;
            chartMarginsLegend1.Right = new Telerik.Reporting.Charting.Styles.Unit(3D, Telerik.Reporting.Charting.Styles.UnitType.Percentage);
            chartMarginsLegend1.Top = new Telerik.Reporting.Charting.Styles.Unit(20D, Telerik.Reporting.Charting.Styles.UnitType.Percentage);
            this.pieChart.Legend.Appearance.Dimensions.Margins = chartMarginsLegend1;
            this.pieChart.Legend.Appearance.ItemTextAppearance.TextProperties.Color = System.Drawing.Color.FromArgb(((int)(((byte)(120)))), ((int)(((byte)(162)))), ((int)(((byte)(19)))));
            this.pieChart.Location = new Telerik.Reporting.Drawing.PointU(new Telerik.Reporting.Drawing.Unit(9.77408504486084D, Telerik.Reporting.Drawing.UnitType.Cm), new Telerik.Reporting.Drawing.Unit(2.5399999618530273D, Telerik.Reporting.Drawing.UnitType.Cm));
            this.pieChart.Name = "pieChart";
            this.pieChart.PlotArea.Appearance.Border.Color = System.Drawing.Color.FromArgb(((int)(((byte)(226)))), ((int)(((byte)(201)))), ((int)(((byte)(156)))));
            this.pieChart.PlotArea.Appearance.Border.Visible = false;
            chartMargins1.Bottom = new Telerik.Reporting.Charting.Styles.Unit(0D, Telerik.Reporting.Charting.Styles.UnitType.Percentage);
            chartMargins1.Left = new Telerik.Reporting.Charting.Styles.Unit(10D, Telerik.Reporting.Charting.Styles.UnitType.Percentage);
            chartMargins1.Right = new Telerik.Reporting.Charting.Styles.Unit(20D, Telerik.Reporting.Charting.Styles.UnitType.Percentage);
            chartMargins1.Top = new Telerik.Reporting.Charting.Styles.Unit(10D, Telerik.Reporting.Charting.Styles.UnitType.Percentage);
            this.pieChart.PlotArea.Appearance.Dimensions.Margins = chartMargins1;
            chartPaddings1.Top = new Telerik.Reporting.Charting.Styles.Unit(0D, Telerik.Reporting.Charting.Styles.UnitType.Pixel);
            this.pieChart.PlotArea.Appearance.Dimensions.Paddings = chartPaddings1;
            this.pieChart.PlotArea.Appearance.FillStyle.MainColor = System.Drawing.Color.Transparent;
            this.pieChart.PlotArea.Appearance.FillStyle.SecondColor = System.Drawing.Color.Transparent;
            this.pieChart.PlotArea.Appearance.SeriesPalette = "Palette1";
            this.pieChart.PlotArea.Appearance.Shadow.Color = System.Drawing.Color.White;
            this.pieChart.PlotArea.XAxis.Appearance.Color = System.Drawing.Color.FromArgb(((int)(((byte)(226)))), ((int)(((byte)(218)))), ((int)(((byte)(202)))));
            this.pieChart.PlotArea.XAxis.Appearance.MajorGridLines.Color = System.Drawing.Color.FromArgb(((int)(((byte)(244)))), ((int)(((byte)(227)))), ((int)(((byte)(195)))));
            this.pieChart.PlotArea.XAxis.Appearance.MajorGridLines.Width = 0F;
            this.pieChart.PlotArea.XAxis.Appearance.MajorTick.Color = System.Drawing.Color.FromArgb(((int)(((byte)(216)))), ((int)(((byte)(184)))), ((int)(((byte)(86)))));
            this.pieChart.PlotArea.XAxis.Appearance.TextAppearance.TextProperties.Color = System.Drawing.Color.FromArgb(((int)(((byte)(78)))), ((int)(((byte)(168)))), ((int)(((byte)(188)))));
            this.pieChart.PlotArea.XAxis.AxisLabel.TextBlock.Appearance.TextProperties.Color = System.Drawing.Color.FromArgb(((int)(((byte)(78)))), ((int)(((byte)(168)))), ((int)(((byte)(188)))));
            this.pieChart.PlotArea.XAxis.MinValue = 1D;
            this.pieChart.PlotArea.YAxis.Appearance.Color = System.Drawing.Color.FromArgb(((int)(((byte)(226)))), ((int)(((byte)(218)))), ((int)(((byte)(202)))));
            this.pieChart.PlotArea.YAxis.Appearance.MajorGridLines.Color = System.Drawing.Color.FromArgb(((int)(((byte)(244)))), ((int)(((byte)(227)))), ((int)(((byte)(195)))));
            this.pieChart.PlotArea.YAxis.Appearance.MajorTick.Color = System.Drawing.Color.FromArgb(((int)(((byte)(216)))), ((int)(((byte)(184)))), ((int)(((byte)(86)))));
            this.pieChart.PlotArea.YAxis.Appearance.MinorGridLines.Color = System.Drawing.Color.FromArgb(((int)(((byte)(244)))), ((int)(((byte)(227)))), ((int)(((byte)(195)))));
            this.pieChart.PlotArea.YAxis.Appearance.MinorTick.Color = System.Drawing.Color.FromArgb(((int)(((byte)(216)))), ((int)(((byte)(184)))), ((int)(((byte)(86)))));
            this.pieChart.PlotArea.YAxis.Appearance.TextAppearance.TextProperties.Color = System.Drawing.Color.FromArgb(((int)(((byte)(78)))), ((int)(((byte)(168)))), ((int)(((byte)(188)))));
            this.pieChart.PlotArea.YAxis.AxisLabel.TextBlock.Appearance.TextProperties.Color = System.Drawing.Color.FromArgb(((int)(((byte)(78)))), ((int)(((byte)(168)))), ((int)(((byte)(188)))));
            chartSeries1.Appearance.Border.Color = System.Drawing.Color.FromArgb(((int)(((byte)(177)))), ((int)(((byte)(215)))), ((int)(((byte)(250)))));
            chartSeries1.Appearance.ExplodePercent = 10;
            chartSeries1.Appearance.FillStyle.FillType = Telerik.Reporting.Charting.Styles.FillType.Solid;
            chartSeries1.Appearance.FillStyle.MainColor = System.Drawing.Color.FromArgb(((int)(((byte)(194)))), ((int)(((byte)(230)))), ((int)(((byte)(252)))));
            chartSeries1.Appearance.LabelAppearance.Dimensions.AutoSize = false;
            chartSeries1.Appearance.LabelAppearance.Dimensions.Height = new Telerik.Reporting.Charting.Styles.Unit(5D, Telerik.Reporting.Charting.Styles.UnitType.Pixel);
            chartSeries1.Appearance.LabelAppearance.Dimensions.Width = new Telerik.Reporting.Charting.Styles.Unit(5D, Telerik.Reporting.Charting.Styles.UnitType.Pixel);
            chartSeries1.Appearance.LabelAppearance.LabelConnectorStyle.Color = System.Drawing.Color.FromArgb(((int)(((byte)(28)))), ((int)(((byte)(58)))), ((int)(((byte)(112)))));
            chartSeries1.Appearance.LabelAppearance.LabelConnectorStyle.EndCap = System.Drawing.Drawing2D.LineCap.ArrowAnchor;
            chartSeries1.Appearance.LabelAppearance.LabelConnectorStyle.StartCap = System.Drawing.Drawing2D.LineCap.ArrowAnchor;
            chartSeries1.Appearance.LabelAppearance.LabelConnectorStyle.Width = 2F;
            chartSeries1.Appearance.LabelAppearance.LabelLocation = Telerik.Reporting.Charting.Styles.StyleSeriesItemLabel.ItemLabelLocation.Outside;
            chartSeries1.Appearance.LabelAppearance.Position.AlignedPosition = Telerik.Reporting.Charting.Styles.AlignedPositions.Center;
            chartSeries1.Appearance.ShowLabelConnectors = true;
            chartSeries1.Appearance.TextAppearance.TextProperties.Color = System.Drawing.Color.FromArgb(((int)(((byte)(78)))), ((int)(((byte)(168)))), ((int)(((byte)(188)))));
            chartSeries1.DataLabelsColumn = "Description";
            chartSeries1.DataYColumn = "Value";
            chartSeries1.Name = "Series 1";
            chartSeries1.Type = Telerik.Reporting.Charting.ChartSeriesType.Pie;
            this.pieChart.Series.AddRange(new Telerik.Reporting.Charting.ChartSeries[] {
            chartSeries1});
            this.pieChart.SeriesPalette = "Palette1";
            this.pieChart.Size = new Telerik.Reporting.Drawing.SizeU(new Telerik.Reporting.Drawing.Unit(16.520584106445312D, Telerik.Reporting.Drawing.UnitType.Cm), new Telerik.Reporting.Drawing.Unit(4.7601766586303711D, Telerik.Reporting.Drawing.UnitType.Cm));
            this.pieChart.Style.Color = System.Drawing.Color.FromArgb(((int)(((byte)(40)))), ((int)(((byte)(84)))), ((int)(((byte)(164)))));
            this.pieChart.Style.TextAlign = Telerik.Reporting.Drawing.HorizontalAlign.Center;
            this.pieChart.Style.VerticalAlign = Telerik.Reporting.Drawing.VerticalAlign.Middle;
            this.pieChart.NeedDataSource += new System.EventHandler(this.pieChart_NeedDataSource);

Please, I need your help,
It is very appreciated to send me the modified code.

Regards,
Bader
0
Accepted
Steve
Telerik team
answered on 15 Aug 2011, 04:45 PM
Hi Bader,

According to the code you have pasted, you've defined or using a built-in palette in the chart which would inevitably interfere with the custom styles you're trying to set with code. Make sure the SeriesPalette property is empty and let us know how this goes.

Regards,
Steve
the Telerik team

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

Tags
General Discussions
Asked by
Bader
Top achievements
Rank 1
Answers by
Steve
Telerik team
Bader
Top achievements
Rank 1
Share this question
or