Unable to set Doughnut Chart sector colors

Hi ,


I want to set custom colors for doughnut chart sectors . Given below is the code i am using to do so :

//populate series
chart.ChartData.Series.Add(fact.GetCell(0, 0, 1, “Score”), ChartTypeEx.Doughtnut);
ChartSeriesEx series = chart.ChartData.Series[0];
series.Labels.ShowValue = true;

// iterate on dataset
for (int j = 0; j < key.xAxis.Length; j++)
{

series.Values.Add(fact.GetCell(0,(j+1),1,double.Parse(key.xAxis[j])));
ChartPointEx point = new ChartPointEx(series);
point.Index = j;
point.Format.Fill.FillType = FillTypeEx.Solid;
System.Drawing.Color chartbackcolor = ColorTranslator.FromHtml(key.Color[j]);
point.Format.Fill.SolidFillColor.Color = chartbackcolor;
//Adding Series Points
series.Points.Add(point);
}


But even after this i am not successful in my attempts , can you please help me out
Thanks !

Hi Ankit,

I have observed the requirements shared by you and suggest you to please try using the following sample code on your end to serve the purpose. Please share, if I may help you further in this regard.

public static void TestDohnutChart()
{
Presentation pres = new Presentation();
ISlide slide = pres.Slides[0];

IChart chart = slide.Shapes.AddChart(ChartType.Doughnut, 10, 10, 400, 400);

IChartSeries series = chart.ChartData.Series[0];

IChartDataPoint point = series.DataPoints[0];
point.Format.Fill.FillType = FillType.Solid;
point.Format.Fill.SolidFillColor.Color = Color.Cyan;
//Setting Sector border
point.Format.Line.FillFormat.FillType = FillType.Solid;
point.Format.Line.FillFormat.SolidFillColor.Color = Color.Gray;
point.Format.Line.Width = 3.0;
point.Format.Line.Style = LineStyle.ThinThick;
point.Format.Line.DashStyle = LineDashStyle.DashDot;


IChartDataPoint point1 = series.DataPoints[1];
point1.Format.Fill.FillType = FillType.Solid;
point1.Format.Fill.SolidFillColor.Color = Color.Brown;

//Setting Sector border
point1.Format.Line.FillFormat.FillType = FillType.Solid;
point1.Format.Line.FillFormat.SolidFillColor.Color = Color.Blue;
point1.Format.Line.Width = 3.0;
point1.Format.Line.Style = LineStyle.Single;
point1.Format.Line.DashStyle = LineDashStyle.LargeDashDot;

IChartDataPoint point2 = series.DataPoints[2];
point2.Format.Fill.FillType = FillType.Solid;
point2.Format.Fill.SolidFillColor.Color = Color.Coral;

//Setting Sector border
point2.Format.Line.FillFormat.FillType = FillType.Solid;
point2.Format.Line.FillFormat.SolidFillColor.Color = Color.Red;
point2.Format.Line.Width = 2.0;
point2.Format.Line.Style = LineStyle.ThinThin;
point2.Format.Line.DashStyle = LineDashStyle.LargeDashDotDot;


//Create custom labels for each of categories for new series

IDataLabel lbl1 = series.DataPoints[0].Label;
// lbl.ShowCategoryName = true;
lbl1.DataLabelFormat.ShowValue = true;


IDataLabel lbl2 = series.DataPoints[1].Label;
lbl2.DataLabelFormat.ShowValue = true;
lbl2.DataLabelFormat.ShowLegendKey = true;
lbl2.DataLabelFormat.ShowPercentage = true;

IDataLabel lbl3 = series.DataPoints[2].Label;
lbl3.DataLabelFormat.ShowSeriesName = true;
lbl3.DataLabelFormat.ShowPercentage = true;


//Showing Leader Lines for Chart
series.Labels.DefaultDataLabelFormat.ShowLeaderLines = true;

//Setting Rotation Angle for Pie Chart Sectors
chart.ChartData.SeriesGroups[0].FirstSliceAngle = 180;

// Save presentation with chart
pres.Save(“D:\Aspose Data\AsposePieChart.pptx”, SaveFormat.Pptx);

}


Many Thanks,