How to explode a doughnut chart in C#

In the previous article, we have demonstrated how to explode a pie chart via Spire.XLS. This article we will explain how to explode a doughnut chart in C#.

When we need to explode a doughnut chart, we can set the chart type as DoughnutExploded when we create a doughnut chart from scratch. For the existing doughnut chart, we can easily change the chart type to explode the doughnut chart.

Step 1: Create an instance of Excel workbook and load the document from file.

Workbook workbook = new Workbook();
workbook.LoadFromFile("DoughnutChart.xlsx",ExcelVersion.Version2010);

Step 2: Get the first worksheet from the sample workbook.

Worksheet sheet = workbook.Worksheets[0];

Step 3: Get the first chart from the first worksheet.

Chart chart = sheet.Charts[0];

Step 4: Set the chart type as DoughnutExploded to explode the doughnut chart.

chart.ChartType = ExcelChartType.DoughnutExploded;

Step 5: Save the document to file.

workbook.SaveToFile("ExplodedDoughnutChart.xlsx", ExcelVersion.Version2010);

Effective screenshot of the explode doughnut chart:

How to explode a doughnut chart in C#

Full codes of how to explode a doughnut chart:

Workbook workbook = new Workbook();
workbook.LoadFromFile("DoughnutChart.xlsx",ExcelVersion.Version2010);

Worksheet sheet = workbook.Worksheets[0];
Chart chart = sheet.Charts[0];
chart.ChartType = ExcelChartType.DoughnutExploded;

workbook.SaveToFile("ExplodedDoughnutChart.xlsx", ExcelVersion.Version2010);