We're sorry Aspose doesn't work properply without JavaScript enabled.

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

@kimmomo ,
Aspose.Cells has replaced Aspose.Excel and provided a large set of APIs to perform a variety of tasks on MS Excel files. It supports all the latest type of charts and respective features. You may try the following sample code and go through the suggested articles for more details for working on charts.

// Instantiating a Workbook object
Workbook workbook = new Workbook();

// Adding a new worksheet to the Excel object
int sheetIndex = workbook.Worksheets.Add();

// Obtaining the reference of the newly added worksheet by passing its sheet index
Worksheet worksheet = workbook.Worksheets[sheetIndex];

// Adding sample values to cells
worksheet.Cells["A1"].PutValue(50);
worksheet.Cells["A2"].PutValue(100);
worksheet.Cells["A3"].PutValue(150);
worksheet.Cells["B1"].PutValue(4);
worksheet.Cells["B2"].PutValue(20);
worksheet.Cells["B3"].PutValue(50);

// Adding a chart to the worksheet
int chartIndex = worksheet.Charts.Add(Aspose.Cells.Charts.ChartType.Pyramid, 5, 0, 15, 5);

// Accessing the instance of the newly added chart
Aspose.Cells.Charts.Chart chart = worksheet.Charts[chartIndex];

// Adding SeriesCollection (chart data source) to the chart ranging from "A1" cell to "B3"
chart.NSeries.Add("A1:B3", true);

// Saving the Excel file
workbook.Save(dataDir + "output.xls");

For more details go through the following links:
Charts

Following is a list of features discussed in this article:

  • Creating and Customizing Charts
  • Setting Chart Appearance
  • Manipulate Position Size and Designer Chart
  • Using Sparklines and Settings 3D Format
  • Chart Rendering
  • Chart Types
  • Controls in Charts
  • Data Formatting in Charts
  • Read and Manipulate Excel 2016 Charts
  • Set the Values Format Code of Chart Series
  • Set the Shape Type of Data Labels of Chart
  • Handle Automatic Units of Chart Axis like Microsoft Excel
  • Read Axis Labels after Calculating the Chart
  • Create Chart PDF with Desired Page Size
  • Find Type of X and Y Values of Points in Chart Series
  • Read Chart Subtitle from ODS File
  • Change Tick Label Direction

Download the latest version of Aspose.Cells for .NET from the following link:
Aspose.Cells for .NET (Latest Version)

You can download the latest demos here.