Aspose Slides Pie Chart colours

Hi,

I am trying to use the code below to create a pie chart and colour the slices individually. However I can not seem to access the format for the for each slice.

How can you change the format for each slice?

Thanks.

Dim Id As Integer = chart.ChartData.Series.Add(fact.GetCell(0, 0, 1, “Series 1”), chart.Type)
Dim series As ChartSeriesEx = chart.ChartData.Series(Id)

While rdr.Read

chart.ChartData.Categories.Add(fact.GetCell(0, intSeriesCounter, 0, rdr.GetString(0)))
series.Values.Add(fact.GetCell(0, intSeriesCounter, 1, rdr.GetValue(1)))
intSeriesCounter += 1

End While
rdr.Close()

For i = 0 To chart.ChartData.Categories.Count - 1

chart.ChartData.Series(i).Format.Fill.FillType = FillTypeEx.Solid
chart.ChartData.Series(i).Format.Fill.SolidFillColor.Color = getSeriesColour(i)

Next

Hi Andrew,

Please see the following documentation link regarding how to set the color of pie chart sectors using Aspose.Slides for .NET.

http://www.aspose.com/docs/display/slidesnet/Setting+Pie+Chart+Sector+Colors

In case you still face any issue, please share your resultant PPTX file with complete code with us. We will check it and get back to you soon.

Thanks & Regards,

Hi,

I have had a look at that code before and get an error ‘Type ‘IChartDataPoint’ is not defined’.

I am creating my charts using ChartEx.

Thanks.

Hi Andrew,

As you are using the legacy version of Aspose.Slides for .NET, please see the following sample code to set the Pie chart sector colors.

Dim pres As New PresentationEx()

'Access first slide
Dim sld As SlideEx = pres.Slides(0)

' Add chart with default data
Dim chart As Aspose.Slides.Pptx.ChartEx =
    sld.Shapes.AddChart(ChartTypeEx.Pie, 100, 100, 400, 400)

'Setting chart Title
chart.ChartTitle.Text.Text = "Sample Title"
chart.ChartTitle.Text.CenterText = True
chart.ChartTitle.Height = 20
chart.HasTitle = True

'Set first series to Show Values
chart.ChartData.Series(0).Labels.ShowValue = True

'Setting the index of chart data sheet
Dim defaultWorksheetIndex As Integer = 0

'Getting the chart data worksheet
Dim fact As ChartDataCellFactory = chart.ChartData.ChartDataCellFactory

'Delete default generated series and categories
chart.ChartData.Series.Clear()
chart.ChartData.Categories.Clear()

'Adding new categories
chart.ChartData.Categories.Add(fact.GetCell(0, 1, 0, "First Qtr"))
chart.ChartData.Categories.Add(fact.GetCell(0, 2, 0, "2nd Qtr"))
chart.ChartData.Categories.Add(fact.GetCell(0, 3, 0, "3rd Qtr"))

'Adding new series
Dim Id As Integer = chart.ChartData.Series.Add(fact.GetCell(0, 0, 1, "Series 1"), chart.Type)

Dim series As ChartSeriesEx = chart.ChartData.Series(Id)

'Now populating series data
series.Values.Add(fact.GetCell(defaultWorksheetIndex, 1, 1, 20))
series.Values.Add(fact.GetCell(defaultWorksheetIndex, 2, 1, 50))
series.Values.Add(fact.GetCell(defaultWorksheetIndex, 3, 1, 30))

'Adding new points and setting sector color
series.IsColorVaried = True
Dim point As New ChartPointEx(series)
point.Index = 0
point.Format.Fill.FillType = FillTypeEx.Solid
point.Format.Fill.SolidFillColor.Color = Color.Cyan

'Setting Sector border
point.Format.Line.FillFormat.FillType = FillTypeEx.Solid
point.Format.Line.FillFormat.SolidFillColor.Color = Color.Gray
point.Format.Line.Width = 3.0
point.Format.Line.Style = LineStyleEx.ThinThick
point.Format.Line.DashStyle = LineDashStyleEx.DashDot

Dim point1 As New ChartPointEx(series)
point1.Index = 1
point1.Format.Fill.FillType = FillTypeEx.Solid
point1.Format.Fill.SolidFillColor.Color = Color.Brown

'Setting Sector border
point1.Format.Line.FillFormat.FillType = FillTypeEx.Solid
point1.Format.Line.FillFormat.SolidFillColor.Color = Color.Blue
point1.Format.Line.Width = 3.0
point1.Format.Line.Style = LineStyleEx.Single
point1.Format.Line.DashStyle = LineDashStyleEx.LargeDashDot

Dim point2 As New ChartPointEx(series)
point2.Index = 2
point2.Format.Fill.FillType = FillTypeEx.Solid
point2.Format.Fill.SolidFillColor.Color = Color.Coral

'Setting Sector border
point2.Format.Line.FillFormat.FillType = FillTypeEx.Solid
point2.Format.Line.FillFormat.SolidFillColor.Color = Color.Red
point2.Format.Line.Width = 2.0
point2.Format.Line.Style = LineStyleEx.ThinThin
point2.Format.Line.DashStyle = LineDashStyleEx.LargeDashDotDot

'Adding Series Points
series.Points.Add(point)
series.Points.Add(point1)
series.Points.Add(point2)

'Create custom labels for each of categories for new series
Dim lbl As New DataLabelEx(series)
' lbl.ShowCategoryName = True
lbl.ShowValue = True
lbl.Id = 0
series.Labels.Add(lbl)

'Showing Leader Lines for Chart
series.Labels.ShowLeaderLines = True

'Setting Rotation Angle for Pie Chart Sectors
chart.ChartData.Series(0).FirstSliceAngle = 180

'Save presentation with chart
pres.Write("C:\data\PieChart.pptx")

In case you still face any issue, please feel free to contact support.

Thanks & Regards,

Hi,

Thank you for the code. I am trying to update my code to the current IChart implementation, but using your first example, but I am getting an error ‘Type IChartDataCellFactory is not defined’.

Thanks.

Hi Andrew,

Please use IChartDataWorkbook instead of IChartDataCellFactory with the latest version of Aspose.Slides for .NET. I have also updated the documentation topic in accordance with this change and your can see the updated documentation topic here as per your requirement.

Thanks & Regards,

Hi,

Thanks for the update.

Andrew.