Chart (46)

When analyzing numeric datasets such as exam scores, sales figures or sensor readings, professionals often need to visualize data distribution. A histogram chart is the standard statistical chart for this purpose.
With Spire.XLS for .NET, C# developers can programmatically create a histogram chart in Excel without installing Microsoft Office on the runtime machine. This tutorial covers:
- What Is a Histogram Chart?
- Setting Up Your Project
- Step-by-Step: C# Histogram Chart Generation
- Full C# Code for Creating a Histogram in Excel
- Frequently Asked Questions
What Is a Histogram Chart?
A histogram chart is a statistical chart that shows how numerical data is distributed across a series of ranges called bins. Instead of plotting every individual value, a histogram groups values into intervals and uses each bar's height to show how many values fall into that interval.
In C# automation scenarios, histogram charts help developers quickly reveal a dataset’s central tendency, value spread, shape, and outliers for reporting purposes.
A typical histogram has three core elements:
| Element | What It Represents |
|---|---|
| X‑axis | The numerical bin intervals — for example, [160, 168), [168, 176), [176, 184) |
| Y‑axis | The frequency or count of values that fall into each bin |
| Bars | One bar per bin; the bar height equals the number of observations in that interval |
Unlike a standard column chart, histogram bars usually touch or have a very small gap because the x‑axis represents a continuous numerical range, not separate categories.
Setting Up Your Project
Before you start, make sure you have:
- Visual Studio (or any .NET IDE)
- .NET Framework 4.5+, .NET Core, or .NET 5+
- Spire.XLS 11.10.5 or later installed via NuGet
Install the package from the Package Manager Console:
Install-Package Spire.XLS
Step-by-Step: C# Histogram Chart Generation
Step 1: Load or Create a Workbook with Data
A histogram requires a range of numerical values. If you already have an Excel file with source data, load it as follows:
Workbook workbook = new Workbook();
workbook.LoadFromFile("Data.xlsx");
Worksheet sheet = workbook.Worksheets[0];
If you prefer to build the data in code, you can create a new workbook and write an array of numbers into a column. Example:
Workbook workbook = new Workbook();
Worksheet sheet = workbook.Worksheets[0];
// Sample raw numeric data: student exam scores
sheet.Range["A1"].Text = "Exam Scores";
double[] scores = { 55, 62, 68, 70, 72, 75, 77, 80, 82, 85, 88, 90, 91, 94, 96 };
for (int i = 0; i < scores.Length; i++)
{
sheet.Range[$"A{i + 2}"].NumberValue = scores[i];
}
Step 2: Add a Chart Object and Set the Type to Histogram
With the data in place, add a chart to the worksheet and explicitly set its type to ExcelChartType.Histogram. This is the core step that tells Spire.XLS to render a histogram rather than a standard column chart.
Chart histogramChart = sheet.Charts.Add();
histogramChart.ChartType = ExcelChartType.Histogram;
✅ Remarks: The ExcelChartType enumeration contains over 70 chart types, including pie chart, bar chart, waterfall chart, etc.
Step 3: Bind the Data Range to Chart
Next, assign the numerical data range to the chart. For a histogram, you typically select a single column of values — the chart engine automatically calculates the frequency distribution for you.
histogramChart.DataRange = sheet.Range["A1:A16"];
Step 4: Configure the Bins (Axis Grouping)
Spire.XLS gives you two primary ways to control binning on the category axis. Enable only one of the following:
// Option A: Set a fixed bin width
histogramChart.PrimaryCategoryAxis.BinWidth = 10;
// Option B: Specify the number of bins
histogramChart.PrimaryCategoryAxis.NumberOfBins = 5;
Step 5: Format the Chart for Readability
Default generated charts often need adjustment for presentation: bar gap, titles, legend, position, and data labels.
// Set Gap Width
histogramChart.Series[0].DataFormat.Options.GapWidth = 6;
// Add Chart and Axis Titles
histogramChart.ChartTitle = "Distribution of Exam Scores";
histogramChart.PrimaryValueAxis.Title = "Frequency";
histogramChart.PrimaryCategoryAxis.Title = "Score Bins";
// Chart position
histogramChart.LeftColumn = 3;
histogramChart.TopRow = 3;
histogramChart.RightColumn = 10;
histogramChart.BottomRow = 20;
// Hide the Legend
histogramChart.HasLegend = false;
// Show data labels
var labels = histogramChart.Series[0].DataPoints.DefaultDataPoint.DataLabels;
labels.HasValue = true;
labels.Size = 9;
Step 6: Save the Workbook
Finally, save the workbook to an .xlsx file. Spire.XLS supports multiple Excel versions, but as histogram charts require Excel 2016 or later; save as ExcelVersion.Version2016 or newer.
workbook.SaveToFile("Histogram_chart.xlsx", ExcelVersion.Version2016);
Full C# Code for Creating a Histogram in Excel
using Spire.Xls;
namespace HistogramChart
{
class Program
{
static void Main(string[] args)
{
// Initialize workbook and worksheet
Workbook workbook = new Workbook();
Worksheet sheet = workbook.Worksheets[0];
// Sample raw numeric data: student exam scores
sheet.Range["A1"].Text = "Exam Scores";
double[] scores = { 55, 62, 68, 70, 72, 75, 77, 80, 82, 85, 88, 90, 91, 94, 96 };
for (int i = 0; i < scores.Length; i++)
{
sheet.Range[$"A{i + 2}"].NumberValue = scores[i];
}
// Add histogram chart to sheet
Chart histogramChart = sheet.Charts.Add();
histogramChart.ChartType = ExcelChartType.Histogram;
// Bind data range to the histogram
histogramChart.DataRange = sheet.Range["A1:A16"];
// Set a Fixed Bin Width
histogramChart.PrimaryCategoryAxis.BinWidth = 10;
// (Optional) Specify the Number of Bins
// histogramChart.PrimaryCategoryAxis.NumberOfBins = 5;
// Set Gap Width
histogramChart.Series[0].DataFormat.Options.GapWidth = 6;
// Add Chart and Axis Titles
histogramChart.ChartTitle = "Distribution of Exam Scores";
histogramChart.PrimaryValueAxis.Title = "Frequency";
histogramChart.PrimaryCategoryAxis.Title = "Score Bins";
// Chart position
histogramChart.LeftColumn = 3;
histogramChart.TopRow = 3;
histogramChart.RightColumn = 10;
histogramChart.BottomRow = 20;
// Hide the Legend
histogramChart.HasLegend = false;
// Show data labels
var labels = histogramChart.Series[0].DataPoints.DefaultDataPoint.DataLabels;
labels.HasValue = true;
labels.Size = 9;
// Save the file
workbook.SaveToFile("Histogram_chart.xlsx", ExcelVersion.Version2016);
workbook.Dispose();
}
}
}
After running the code, open the Histogram_chart.xlsx file, you will see a fully rendered histogram with the bin settings, titles, and formatting applied.

Frequently Asked Questions
Q: What is the difference between BinWidth and NumberOfBins?
- BinWidth fixes the width of each interval and calculates the number of bins automatically.
- NumberOfBins fixes the number of intervals and calculates the width automatically.
For histograms, you generally use one or the other depending on whether you want consistent interval sizes or a specific level of detail.
Q: Does Spire.XLS support exporting the histogram to PDF or images?
Yes. After building the chart, you can call workbook.SaveToFile("output.pdf", FileFormat.PDF) or use the chart‑to‑image conversion methods to export the chart as an image for reports or web dashboards.
Q: Can I create multiple histograms in one workbook?
Yes. Add separate charts to worksheets or to different positions on the same sheet. For multiple distributions, creating one histogram per numeric column is usually clearer than combining them.
Q: Is a histogram the same as a column chart?
No. A histogram shows the distribution of continuous numerical data across bins; a column chart compares values across separate categories.
Conclusion
Making a histogram chart in Excel with C# is a straightforward process when you use Spire.XLS for .NET. By following the steps in this guide, developers can embed automated histogram generation directly into .NET workflows, eliminating manual chart creation in Excel. It supports flexible customization of axes, styles, and chart titles to fit different reporting and data analysis requirements.
Explore the official documentation for additional charting and Excel‑processing capabilities.
Waterfall charts in Excel are graphs that visually show how a series of consecutive positive or negative values contribute to the final outcome. They are a useful tool for tracking company profits or cash flow, comparing product revenues, analyzing sales and inventory changes over time, etc. In this article, you will learn how to create a waterfall chart in Excel in C# and VB.NET using Spire.XLS for .NET.
Install Spire.XLS for .NET
To begin with, you need to add the DLL files included in the Spire.XLS for .NET package as references in your .NET project. The DLL files can be either downloaded from this link or installed via NuGet.
PM> Install-Package Spire.XLS
Create a Waterfall Chart in Excel in C# and VB.NET
Waterfall/bridge charts are ideal for analyzing financial statements. To add a waterfall chart to an Excel worksheet, Spire.XLS for .NET provides the Worksheet.Charts.Add(ExcelChartType.WaterFall) method. The following are the detailed steps.
- Create a Workbook instance.
- Load a sample Excel document using Workbook.LoadFromFile() method.
- Get a specified worksheet by its index using Workbook.Worksheets[sheetIndex] property.
- Add a waterfall chart to the worksheet using Worksheet.Charts.Add(ExcelChartType.WaterFall) method.
- Set data range for the chart using Chart.DataRange property.
- Set position and title of the chart.
- Get a specified data series of the chart and then set specific data points in the chart as totals or subtotals using ChartSerie.DataPoints[int index].SetAsTotal property.
- Show the connector lines between data points by setting the ChartSerie.Format.ShowConnectorLines property to true.
- Show data labels for data points, and set the legend position of the chart.
- Save the result document using Workbook.SaveToFile() method.
- C#
- VB.NET
using Spire.Xls;
namespace WaterfallChart
{
class Program
{
static void Main(string[] args)
{
//Create a Workbook instance
Workbook workbook = new Workbook();
//Load a sample Excel document
workbook.LoadFromFile("Data.xlsx");
//Get the first worksheet
Worksheet sheet = workbook.Worksheets[0];
//Add a waterfall chart to the the worksheet
Chart chart = sheet.Charts.Add(ExcelChartType.WaterFall);
//Set data range for the chart
chart.DataRange = sheet["A2:B11"];
//Set position of the chart
chart.LeftColumn = 4;
chart.TopRow = 2;
chart.RightColumn = 15;
chart.BottomRow = 23;
//Set the chart title
chart.ChartTitle = "Income Statement";
//Set specific data points in the chart as totals or subtotals
chart.Series[0].DataPoints[2].SetAsTotal = true;
chart.Series[0].DataPoints[7].SetAsTotal = true;
chart.Series[0].DataPoints[9].SetAsTotal = true;
//Show the connector lines between data points
chart.Series[0].Format.ShowConnectorLines = true;
//Show data labels for data points
chart.Series[0].DataPoints.DefaultDataPoint.DataLabels.HasValue = true;
chart.Series[0].DataPoints.DefaultDataPoint.DataLabels.Size = 8;
//Set the legend position of the chart
chart.Legend.Position = LegendPositionType.Top;
//Save the result document
workbook.SaveToFile("WaterfallChart.xlsx");
}
}
}

Apply for a Temporary License
If you'd like to remove the evaluation message from the generated documents, or to get rid of the function limitations, please request a 30-day trial license for yourself.
This article will show you how to use Spire.XLS for .NET to create a bubble chart in Excel in C# and VB.NET.
using Spire.Xls;
namespace BubbleChart
{
class Program
{
static void Main(string[] args)
{
//Create a new workbook
Workbook workbook = new Workbook();
//Add a worksheet and set name
workbook.CreateEmptySheets(1);
Worksheet sheet = workbook.Worksheets[0];
sheet.Name = "Chart data";
//Initialize chart and set its type
Chart chart = sheet.Charts.Add(ExcelChartType.Bubble);
//Set the position of the chart in the worksheet
chart.LeftColumn = 1;
chart.RightColumn = 10;
chart.TopRow = 1;
chart.BottomRow = 20;
//Set title for the chart and values
Spire.Xls.Charts.ChartSerie cs1 = chart.Series.Add("Bubble Chart");
cs1.EnteredDirectlyValues = new object[] { 2.2, 5.6 };
cs1.EnteredDirectlyCategoryLabels = new object[] { 1.1, 4.4 };
cs1.EnteredDirectlyBubbles = new object[] { 3, 6 };
//Save the document to file
workbook.SaveToFile("Output.xlsx", ExcelVersion.Version2010);
}
}
}
Imports Spire.Xls
Namespace BubbleChart
Class Program
Private Shared Sub Main(ByVal args() As String)
'Create a new workbook
Dim workbook As Workbook = New Workbook
'Add a worksheet and set name
workbook.CreateEmptySheets(1)
Dim sheet As Worksheet = workbook.Worksheets(0)
sheet.Name = "Chart data"
'Initialize chart and set its type
Dim chart As Chart = sheet.Charts.Add(ExcelChartType.Bubble)
'Set the position of the chart in the worksheet
chart.LeftColumn = 1
chart.RightColumn = 10
chart.TopRow = 1
chart.BottomRow = 20
'Set title for the chart and values
Dim cs1 As Spire.Xls.Charts.ChartSerie = chart.Series.Add("Bubble Chart")
cs1.EnteredDirectlyValues = New Object() {2.2, 5.6}
cs1.EnteredDirectlyCategoryLabels = New Object() {1.1, 4.4}
cs1.EnteredDirectlyBubbles = New Object() {3, 6}
'Save the document to file
workbook.SaveToFile("Output.xlsx", ExcelVersion.Version2010)
End Sub
End Class
End Namespace
Effective screenshot of Excel Bubble chart:

A Pivot Chart is a graphical representation of a Pivot Table. While a Pivot Table summarizes data and allows users to manipulate it for analysis, a Pivot Chart provides a visual representation of that summarized data. Pivot Charts can be easily updated as the data in the Pivot Table changes, making them an essential tool for reporting and analysis. In this article, we will demonstrate how to create pivot charts in Excel in C# using Spire.XLS for .NET.
- Create Pivot Charts in Excel in C#
- Show or Hide Field Buttons in Pivot Charts in Excel in C#
- Format Pivot Chart Series in Excel in C#
Install Spire.XLS for .NET
To begin with, you need to add the DLL files included in the Spire.XLS for .NET package as references in your .NET project. The DLL files can be either downloaded from this link or installed via NuGet.
PM> Install-Package Spire.XLS
Create Pivot Charts in Excel in C#
With Spire.XLS for .NET, creating a pivot chart from an existing pivot table in Excel is straightforward using the Worksheet.Charts.Add(ExcelChartType pivotChartType, IPivotTable pivotTable) method. The detailed steps are as follows.
- Create an object of the Workbook class.
- Load an Excel file using Workbook.LoadFromFile() method.
- Get a specific worksheet in the Excel file using Workbook.Worksheets[index] property.
- Get a specific pivot table in the worksheet using Worksheet.PivotTables[index] property.
- Add a pivot chart based on the pivot table to the worksheet using Worksheet.Charts.Add(ExcelChartType pivotChartType, IPivotTable pivotTable) method.
- Set the position and title of the pivot chart.
- Save the resulting file using Workbook.SaveToFile() method.
- C#
using Spire.Xls;
using Spire.Xls.Core;
namespace CreatePivotChart
{
internal class Program
{
static void Main(string[] args)
{
// Create a Workbook object
Workbook workbook = new Workbook();
// Load an Excel file
workbook.LoadFromFile("PivotTable.xlsx");
// Get the first worksheet
Worksheet sheet = workbook.Worksheets[0];
// Get the first pivot table in the worksheet
IPivotTable pivotTable = sheet.PivotTables[0];
// Create a clustered column chart based on the pivot table
Chart pivotChart = sheet.Charts.Add(ExcelChartType.ColumnClustered, pivotTable);
// Set chart position
pivotChart.TopRow = 1;
pivotChart.LeftColumn = 11;
pivotChart.RightColumn = 20;
pivotChart.BottomRow = 15;
// Set chart title to null
pivotChart.ChartTitle = "";
// Save the resulting file
workbook.SaveToFile("CreatePivotChart.xlsx", ExcelVersion.Version2013);
workbook.Dispose();
}
}
}

Show or Hide Field Buttons in Pivot Charts in Excel in C#
Using Spire.XLS for .NET, you can easily show or hide different types of field buttons to customize the appearance of your charts. The field buttons you can control include:
- Entire Field Buttons
- Report Filter Field Buttons
- Legend Field Buttons
- Axis Field Buttons
- Value Field Buttons
The detailed steps are as follows:
- Create an object of the Workbook class.
- Load an Excel file using Workbook.LoadFromFile() method.
- Get a specific worksheet in the Excel file using Workbook.Worksheets[index] property.
- Get a specific pivot table in the worksheet using Worksheet.PivotTables[index] property.
- Add a pivot chart based on the pivot table to the worksheet using Worksheet.Charts.Add(ExcelChartType pivotChartType, IPivotTable pivotTable) method.
- Set the position and title of the pivot chart.
- Hide specific field buttons in the pivot chart, such as the axis field buttons and the value field buttons, using Chart.DisplayAxisFieldButtons and Chart.DisplayValueFieldButtons properties.
- Save the resulting file using Workbook.SaveToFile() method.
- C#
using Spire.Xls;
using Spire.Xls.Core;
namespace ShowOrHideFieldButtons
{
internal class Program
{
static void Main(string[] args)
{
// Create a Workbook object
Workbook workbook = new Workbook();
// Load an Excel file
workbook.LoadFromFile("CreatePivotChart.xlsx");
// Get the first worksheet
Worksheet sheet = workbook.Worksheets[0];
// Get the first pivot table in the worksheet
IPivotTable pivotTable = sheet.PivotTables[0];
// Create a clustered column chart based on the pivot table
Chart pivotChart = sheet.Charts.Add(ExcelChartType.ColumnClustered, pivotTable);
// Set chart position
pivotChart.TopRow = 1;
pivotChart.LeftColumn = 11;
pivotChart.RightColumn = 20;
pivotChart.BottomRow = 15;
// Set chart title to null
pivotChart.ChartTitle = "";
// Hide specific field buttons
pivotChart.DisplayAxisFieldButtons = false;
pivotChart.DisplayValueFieldButtons = false;
// pivotChart.DisplayLegendFieldButtons = false;
// pivotChart.ShowReportFilterFieldButtons = false;
// pivotChart.DisplayEntireFieldButtons = false;
// Save the resulting file
workbook.SaveToFile("HideFieldButtons.xlsx", ExcelVersion.Version2013);
workbook.Dispose();
}
}
}

Format Pivot Chart Series in Excel in C#
When creating a pivot chart in Excel from a pivot table using Spire.XLS for .NET, it's important to note that the chart series do not get generated automatically. Instead, you must manually add the series and format them according to your preferences. The detailed steps are as follows:
- Create an object of the Workbook class.
- Load an Excel file using Workbook.LoadFromFile() method.
- Get a specific worksheet in the Excel file using Workbook.Worksheets[index] property.
- Get a specific pivot table in the worksheet using Worksheet.PivotTables[index] property.
- Add a pivot chart based on the pivot table to the worksheet using Worksheet.Charts.Add(ExcelChartType pivotChartType, IPivotTable pivotTable) method.
- Set the position and title of the pivot chart.
- Add series to the chart using Chart.Series.Add() method and then apply the desired formatting to the series.
- Save the resulting file using Workbook.SaveToFile() method.
- C#
using Spire.Xls;
using Spire.Xls.Charts;
using Spire.Xls.Core;
namespace FormatChartSeries
{
internal class Program
{
static void Main(string[] args)
{
// Create a Workbook object
Workbook workbook = new Workbook();
// Load an Excel file
workbook.LoadFromFile("CreatePivotChart.xlsx");
// Get the first worksheet
Worksheet sheet = workbook.Worksheets[0];
// Get the first pivot table in the worksheet
IPivotTable pivotTable = sheet.PivotTables[0];
// Create a clustered column chart based on the pivot table
Chart pivotChart = sheet.Charts.Add(ExcelChartType.ColumnClustered, pivotTable);
// Set chart position
pivotChart.TopRow = 1;
pivotChart.LeftColumn = 11;
pivotChart.RightColumn = 20;
pivotChart.BottomRow = 15;
// Set chart title to null
pivotChart.ChartTitle = "";
// Add chart series
ChartSerie series = pivotChart.Series.Add(ExcelChartType.ColumnClustered);
// Set bar width
series.GetCommonSerieFormat().GapWidth = 10;
// Set overlap (uncomment the line below to enable)
// series.GetCommonSerieFormat().Overlap = 100;
// Save the resulting file
workbook.SaveToFile("FormatChartSeries.xlsx", ExcelVersion.Version2013);
workbook.Dispose();
}
}
}

Apply for a Temporary License
If you'd like to remove the evaluation message from the generated documents, or to get rid of the function limitations, please request a 30-day trial license for yourself.
This article demonstrates how to create a chart without reference to the worksheet data range using Spire.XLS.
Detail steps:
Step 1: Create a workbook and get the first worksheet.
Workbook wb = new Workbook(); Worksheet sheet = wb.Worksheets[0];
Step 2: Add a chart to the worksheet.
Chart chart = sheet.Charts.Add();
Step 3: Add a series to the chart.
var series = chart.Series.Add();
Step 4: Add data.
series.EnteredDirectlyValues = new object[] { 10, 20, 30 };
Step 5: Save the file.
wb.SaveToFile("result.xlsx", ExcelVersion.Version2013);
Output:

Full code:
using Spire.Xls;
namespace Create_chart
{
class Program
{
static void Main(string[] args)
{
//Create a workbook
Workbook wb = new Workbook();
//Get the first worksheet
Worksheet sheet = wb.Worksheets[0];
//Add a chart to the worksheet
Chart chart = sheet.Charts.Add();
//Add a series to the chart
var series = chart.Series.Add();
//Add data
series.EnteredDirectlyValues = new object[] { 10, 20, 30 };
//Save the file
wb.SaveToFile("result.xlsx", ExcelVersion.Version2013);
}
}
}
This article elaborates the steps to apply soft edges effect to an excel chart using Spire.XLS.
The example Excel file we used for demonstration:

Detail steps:
Step 1: Instantiate a Workbook object and load the excel file.
Workbook workbook = new Workbook();
workbook.LoadFromFile("Input.xlsx");
Step 2: Get the first worksheet.
Worksheet sheet = workbook.Worksheets[0];
Step 3: Get the chart.
IChart chart = sheet.Charts[0];
Step 4: Specify the size of the soft edge. Value can be set from 0 to 100.
chart.ChartArea.Shadow.SoftEdge = 10;
Step 5: Save the file.
workbook.SaveToFile("Output.xlsx", ExcelVersion.Version2013);
Output:

Full code:
using Spire.Xls;
using Spire.Xls.Core;
namespace Soft_Edges_in_Excel_Chart
{
class Program
{
static void Main(string[] args)
{
//Instantiate a Workbook object
Workbook workbook = new Workbook();
//Load the Excel file
workbook.LoadFromFile("Input.xlsx");
//Get the first worksheet
Worksheet sheet = workbook.Worksheets[0];
//Get the chart
IChart chart = sheet.Charts[0];
//Specify the size of the soft edge. Value can be set from 0 to 100
chart.ChartArea.Shadow.SoftEdge = 10;
//Save the file
workbook.SaveToFile("Output.xlsx", ExcelVersion.Version2013);
}
}
}
Delete Legend and Specific Legend Entries from Excel Chart in C#
2018-03-12 07:55:52 Written by KoohjiA legend is displayed in the chart area by default. However it can be removed from the chart. With Spire.XLS, we can delete the whole legend as well as specific legend entries from Excel chart. This article is going to demonstrate how we can use Spire.XLS to accomplish this function.
Below screenshot shows the Excel chart we used for demonstration:

Delete the whole legend
using Spire.Xls;
namespace DeleteLegend
{
class Program
{
static void Main(string[] args)
{
//Create a Workbook instance
Workbook workbook = new Workbook();
//Load the Excel file
workbook.LoadFromFile("sample.xlsx");
//Get the first worksheet
Worksheet sheet = workbook.Worksheets[0];
//Get the chart
Chart chart = sheet.Charts[0];
//Delete legend from the chart
chart.Legend.Delete();
//Save the file
workbook.SaveToFile("DeleteLegend.xlsx", ExcelVersion.Version2013);
}
}
}
Screenshot:

Delete specific legend entries
using Spire.Xls;
namespace DeleteLegend
{
class Program
{
static void Main(string[] args)
{
//Create a Workbook instance
Workbook workbook = new Workbook();
//Load the Excel file
workbook.LoadFromFile("sample.xlsx");
//Get the first worksheet
Worksheet sheet = workbook.Worksheets[0];
//Get the chart
Chart chart = sheet.Charts[0];
//Delete the first and the second legend entries from the chart
chart.Legend.LegendEntries[0].Delete();
chart.Legend.LegendEntries[1].Delete();
//Save the file
workbook.SaveToFile("DeleteLegendEntries.xlsx", ExcelVersion.Version2013);
}
}
}
Screenshot:

Multi-level category chart is a chart type that has both main category and subcategory labels. This type of chart is useful when you have figures for items that belong to different categories. In this article, you will learn how to create a multi-level category chart in Excel using Spire.XLS with C# and VB.NET.
Step 1: Create a Workbook instance and get the first worksheet.
Workbook wb = new Workbook(); Worksheet sheet = wb.Worksheets[0];
Step 2: Write data to cells.
sheet.Range["A1"].Text = "Main Category"; sheet.Range["A2"].Text = "Fruit"; sheet.Range["A6"].Text = "Vegies"; sheet.Range["B1"].Text = "Sub Category"; sheet.Range["B2"].Text = "Bananas"; sheet.Range["B3"].Text = "Oranges"; sheet.Range["B4"].Text = "Pears"; sheet.Range["B5"].Text = "Grapes"; sheet.Range["B6"].Text = "Carrots"; sheet.Range["B7"].Text = "Potatoes"; sheet.Range["B8"].Text = "Celery"; sheet.Range["B9"].Text = "Onions"; sheet.Range["C1"].Text = "Value"; sheet.Range["C2"].Value = "52"; sheet.Range["C3"].Value = "65"; sheet.Range["C4"].Value = "50"; sheet.Range["C5"].Value = "45"; sheet.Range["C6"].Value = "64"; sheet.Range["C7"].Value = "62"; sheet.Range["C8"].Value = "89"; sheet.Range["C9"].Value = "57";
Step 3: Vertically merge cells from A2 to A5, A6 to A9.
sheet.Range["A2:A5"].Merge(); sheet.Range["A6:A9"].Merge();
Step 4: Add a clustered bar chart to worksheet.
Chart chart = sheet.Charts.Add(ExcelChartType.BarClustered); chart.ChartTitle = "Value"; chart.PlotArea.Fill.FillType = ShapeFillType.NoFill; chart.Legend.Delete();
Step 5: Set the data source of series data.
chart.DataRange = sheet.Range["C2:C9"]; chart.SeriesDataFromRange = false;
Step 6: Set the data source of category labels.
ChartSerie serie = chart.Series[0]; serie.CategoryLabels = sheet.Range["A2:B9"];
Step 7: Show multi-level category labels.
chart.PrimaryCategoryAxis.MultiLevelLable = true;
Step 8: Save the file.
wb.SaveToFile("output.xlsx", ExcelVersion.Version2013);
Output:

Full Code:
using Spire.Xls;
using Spire.Xls.Charts;
namespace CreateMutilLevelChart
{
class Program
{
static void Main(string[] args)
{
Workbook wb = new Workbook();
Worksheet sheet = wb.Worksheets[0];
sheet.Range["A1"].Text = "Main Category";
sheet.Range["A2"].Text = "Fruit";
sheet.Range["A6"].Text = "Vegies";
sheet.Range["B1"].Text = "Sub Category";
sheet.Range["B2"].Text = "Bananas";
sheet.Range["B3"].Text = "Oranges";
sheet.Range["B4"].Text = "Pears";
sheet.Range["B5"].Text = "Grapes";
sheet.Range["B6"].Text = "Carrots";
sheet.Range["B7"].Text = "Potatoes";
sheet.Range["B8"].Text = "Celery";
sheet.Range["B9"].Text = "Onions";
sheet.Range["C1"].Text = "Value";
sheet.Range["C2"].Value = "52";
sheet.Range["C3"].Value = "65";
sheet.Range["C4"].Value = "50";
sheet.Range["C5"].Value = "45";
sheet.Range["C6"].Value = "64";
sheet.Range["C7"].Value = "62";
sheet.Range["C8"].Value = "89";
sheet.Range["C9"].Value = "57";
sheet.Range["A2:A5"].Merge();
sheet.Range["A6:A9"].Merge();
sheet.AutoFitColumn(1);
sheet.AutoFitColumn(2);
Chart chart = sheet.Charts.Add(ExcelChartType.BarClustered);
chart.ChartTitle = "Value";
chart.PlotArea.Fill.FillType = ShapeFillType.NoFill;
chart.Legend.Delete();
chart.LeftColumn = 5;
chart.TopRow = 1;
chart.RightColumn = 14;
chart.DataRange = sheet.Range["C2:C9"];
chart.SeriesDataFromRange = false;
ChartSerie serie = chart.Series[0];
serie.CategoryLabels = sheet.Range["A2:B9"];
chart.PrimaryCategoryAxis.MultiLevelLable = true;
wb.SaveToFile("output.xlsx", ExcelVersion.Version2013);
}
}
}
Imports Spire.Xls
Imports Spire.Xls.Charts
Namespace CreateMutilLevelChart
Class Program
Private Shared Sub Main(args As String())
Dim wb As New Workbook()
Dim sheet As Worksheet = wb.Worksheets(0)
sheet.Range("A1").Text = "Main Category"
sheet.Range("A2").Text = "Fruit"
sheet.Range("A6").Text = "Vegies"
sheet.Range("B1").Text = "Sub Category"
sheet.Range("B2").Text = "Bananas"
sheet.Range("B3").Text = "Oranges"
sheet.Range("B4").Text = "Pears"
sheet.Range("B5").Text = "Grapes"
sheet.Range("B6").Text = "Carrots"
sheet.Range("B7").Text = "Potatoes"
sheet.Range("B8").Text = "Celery"
sheet.Range("B9").Text = "Onions"
sheet.Range("C1").Text = "Value"
sheet.Range("C2").Value = "52"
sheet.Range("C3").Value = "65"
sheet.Range("C4").Value = "50"
sheet.Range("C5").Value = "45"
sheet.Range("C6").Value = "64"
sheet.Range("C7").Value = "62"
sheet.Range("C8").Value = "89"
sheet.Range("C9").Value = "57"
sheet.Range("A2:A5").Merge()
sheet.Range("A6:A9").Merge()
sheet.AutoFitColumn(1)
sheet.AutoFitColumn(2)
Dim chart As Chart = sheet.Charts.Add(ExcelChartType.BarClustered)
chart.ChartTitle = "Value"
chart.PlotArea.Fill.FillType = ShapeFillType.NoFill
chart.Legend.Delete()
chart.LeftColumn = 5
chart.TopRow = 1
chart.RightColumn = 14
chart.DataRange = sheet.Range("C2:C9")
chart.SeriesDataFromRange = False
Dim serie As ChartSerie = chart.Series(0)
serie.CategoryLabels = sheet.Range("A2:B9")
chart.PrimaryCategoryAxis.MultiLevelLable = True
wb.SaveToFile("output.xlsx", ExcelVersion.Version2013)
End Sub
End Class
End Namespace
With Spire.XLS, we can set the 3-D rotation easily in C#. The following code example explains how to set the rotation of the 3D chart view in C#. We will use 3D pie chart for example. Firstly, view the original 3D pie chart:

Code snippet of how to set the 3D rotation for Excel Chart:
Step 1: Create a new instance of workbook and load the sample document from file.
Workbook workbook = new Workbook();
workbook.LoadFromFile("Sample.xlsx");
Step 2: Get the chart from the first worksheet.
Worksheet sheet = workbook.Worksheets[0]; Chart chart = sheet.Charts[0];
Step 3: Set Rotation of the 3D chart view for X and Y.
//X rotation: chart.Rotation=30; //Y rotation: chart.Elevation = 20;
Step 4: Save the document to file.
workbook.SaveToFile("Result.xlsx", ExcelVersion.Version2010);
Effective screenshot of the Excel 3D chart rotation:

Full codes:
using Spire.Xls;
namespace SetRotation
{
class Program
{
static void Main(string[] args)
{
Workbook workbook = new Workbook();
workbook.LoadFromFile("Sample.xlsx");
Worksheet sheet = workbook.Worksheets[0];
Chart chart = sheet.Charts[0];
//X rotation:
chart.Rotation = 30;
//Y rotation:
chart.Elevation = 20;
workbook.SaveToFile("Result.xlsx", ExcelVersion.Version2010);
}
}
}
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:

Full codes of how to explode a doughnut chart:
using Spire.Xls;
namespace ExplodeDoughnut
{
class Program
{
static void Main(string[] args)
{
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);
}
}
}