var workbook = Workbook.Create( ChartSample.ChartSampleOutputDirectory + @"AddCharts.xlsx" );
// Gets the first Worksheet. A Workbook always contains at least 1 Worksheet.
var worksheet = workbook.Worksheets[ 0 ];
// Adds Values for Category.
worksheet.Cells[ "B4" ].Value = 2020;
worksheet.Cells[ "B5" ].Value = 2021;
worksheet.Cells[ "B6" ].Value = 2022;
worksheet.Cells[ "B7" ].Value = 2023;
worksheet.Cells[ "B8" ].Value = 2024;
// Adds a PieChart with the generic Add method. The size of the Chart will be from Cell E4 to L18.
var pieChart = worksheet.Charts.Add<PieChart>( "E4", "L18" );
// Sets the Chart's Title.
pieChart.Title.Text = "IBM Profits";
pieChart.Title.TextOptions.Font.Bold = true;
// Sets the Legend.
pieChart.Legend.Position = LegendPositionType.Right;
// Sets the Category data(x values) for the PieChart : Cells B4 to B8.
pieChart.CategoryData = CategoryData.FromCells( worksheet, "B4", "B8" );
// Adds PieSeries to the PieChart (y values) by specifying fixed values.
var pieSeries = pieChart.SeriesCollection.AddFromValues<PieSeries>( 5, 10, 15, 20, 40 );
// Explodes the slices by 10%.
pieSeries.Explosion = 10;
// Customizes the Stroke of each of the pie slices.
pieSeries.Stroke.Width = 2;
pieSeries.Stroke.Color = Xceed.Drawing.Color.Black;
// Displays & customizes the DataPointLabels.
pieSeries.DataPointLabels.ShowValue = true;
pieSeries.DataPointLabels.Position = PieSliceDataPointLabelsPositionType.OutsideEnd;
pieSeries.DataPointLabels.TextOptions.CustomFormat = "0.0";
// Saves Workbook to disk.
workbook.Save();
Target Platforms: Windows 11, Windows 10, Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2