Free Support Forum - aspose.com

Sales By Category Convert to Pie Chart Failure

Hi,

Regarding to the Chart in Sales by Category demo, I can’t convert it into pie chart by clicking the bar chart and change chart type.

If I generate the chart again by highlighting the cells, and select the insert chart from the menu. I am able to create the pie chart.

Could you advise why?

Thanks,
Kim

Dear Kim,

Thanks for your consideration.

Please modify this line of code in CreatChart method of the demo:

string startCell = excel.GetCellName(4, currentColumn);

Change it to:

string startCell = excel.GetCellName(4, currentColumn + 1);

Then have a try.

I have changed the code as following, but still doesn’t work

Please advise if I misunderstand your reply.

Thanks,
Kim

Private Sub CreateChart(ByVal Excel As Excel, ByVal sheet As Worksheet, ByVal currentRow As Integer, ByVal currentColumn As Integer)
Dim chartIndex As Integer = sheet.Charts.Add(ChartType.Pie, 4, currentColumn + 3, 26, currentColumn + 14)
Dim chart As chart = sheet.Charts(chartIndex)
chart.IsLegendShown = False
Dim startCell As String = Excel.GetCellName(4, currentColumn)
Dim endCell As String = Excel.GetCellName(currentRow, currentColumn + 1)
chart.NSeries.Add(startCell + “:” + endCell, True)
Dim fillFormat As fillFormat = chart.PlotArea.Area.FillFormat
fillFormat.SetPresetColorGradient(GradientPresetType.Daybreak, GradientStyleType.Vertical, 1)

startCell = Excel.GetCellName(4, currentColumn + 1)
endCell = Excel.GetCellName(currentRow, currentColumn)
chart.NSeries.CategoryData = startCell + “:” + endCell
End Sub

Dear Kim,

Please try the following code:

Private Sub CreateChart(ByVal Excel As Excel, ByVal sheet As Worksheet, ByVal currentRow As Integer, ByVal currentColumn As Integer)
Dim chartIndex As Integer = sheet.Charts.Add(ChartType.Bar, 4, currentColumn + 3, 26, currentColumn + 14)
Dim chart As chart = sheet.Charts(chartIndex)
chart.IsLegendShown = False
Dim startCell As String = Excel.GetCellName(4, currentColumn + 1)
Dim endCell As String = Excel.GetCellName(currentRow, currentColumn + 1)
chart.NSeries.Add(startCell + “:” + endCell, True)
Dim fillFormat As fillFormat = chart.PlotArea.Area.FillFormat
fillFormat.SetPresetColorGradient(GradientPresetType.Daybreak, GradientStyleType.Vertical, 1)

startCell = Excel.GetCellName(4, currentColumn)
endCell = Excel.GetCellName(currentRow, currentColumn)
chart.NSeries.CategoryData = startCell + “:” + endCell
End Sub