How to explode a pie chart sections in C#

2016-01-05 08:43:10 Written by  support iceblue
Rate this item
(0 votes)

When we work with Excel pie chart, we may need to separate each part of pie chart to make them stand out. Spire.XLS offers a property of Series.DataFormat.Percent to enable developers to pull the whole pie apart. It also offers a property of Series.DataPoints.DataFormat.Percent to pull apart a single slice from the whole pie chart.

This article is going to introduce the method of how to set the separation width between slices in pie chart in C# by using Spire.XLS.

On MS Excel, We can adjust the percentage of "Pie Explosion" on the Series Options at the "format data series" area to control the width between each section in the chart.

How to explode a pie chart sections in C#

Code Snippet of how to set the separation width between slices in pie chart.

using Spire.Xls;
namespace ExplodePieChart
{

    class Program
    {

        static void Main(string[] args)
        {
            Workbook workbook = new Workbook();
            workbook.LoadFromFile("Sample.xlsx");

            Worksheet ws = workbook.Worksheets[0];
            Chart chart = ws.Charts[0];

            // Set the separation width between slices in pie chart.
            for (int i = 0; i < chart.Series.Count; i++)
            {
                chart.Series[i].DataFormat.Percent = 20;
            }

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

        }
    }
}

Effective screenshot after pull the whole pie apart.

How to explode a pie chart sections in C#

Code Snippet of how to split a single slice from the whole pie chart.

using Spire.Xls;
namespace ExplodePieChart
{

    class Program
    {

        static void Main(string[] args)
        {
            {
                Workbook workbook = new Workbook();
                workbook.LoadFromFile("Sample.xlsx");

                Worksheet ws = workbook.Worksheets[0];
                Chart chart = ws.Charts[0];

                chart.Series[0].DataPoints[0].DataFormat.Percent = 20;

                workbook.SaveToFile("ExplodePieChart.xlsx", ExcelVersion.Version2013);
            }


        }
    }
}

Effective screenshot after pull a single part from the pie chart apart.

How to explode a pie chart sections in C#

Additional Info

  • tutorial_title: Explode a pie chart sections
Last modified on Monday, 06 September 2021 02:12