We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

# How to create Excel combination chart in C#, VB.Net?

Platform: WinForms |
Control: XlsIO |
Published Date: February 14, 2018 |
Last Revised Date: April 12, 2019
Tags:

This article explains how to create combination chart in Excel using Syncfusion Excel (XlsIO) library.

## What is a combination chart?

Combination charts combine two or more chart types to make the data easy to understand. These charts can be used charts when the numbers in your data vary widely from data series to data series, or you have mixed type of data.

Combination Chart

To create a combination chart in Excel using XlsIO, you need to do the following steps.

## Steps to create combination chart:

### Step 1: Initialize chart

Create a chart object by calling the worksheet.Charts.Add method.

C#

```            //Create the chart
```

### Step 2: Assign data

Set a range of data from the worksheet to chart’s DataRange property. To plot the series values in column and categories in row, set chart’s IsSeriesInRows property to false.

C#

```          //Set region of Chart data
chart.DataRange = worksheet["A1:C13"];

//Set chart series in column for assigned data region
chart.IsSeriesInRows = false;
```

### Step 3: Select SerieType to create a combination chart

Set different SerieType value to the series. By doing this, chart type will be changed to combination chart type.

C#

```            //Set Serie type
IChartSerie serie1 = chart.Series[0];
IChartSerie serie2 = chart.Series[1];
serie1.SerieType = ExcelChartType.Column_Clustered;
serie2.SerieType = ExcelChartType.Line;
serie2.UsePrimaryAxis = false;
```

Note:

For creating a combination chart, the chart must have minimum two series. Setting different SerieType property or UsePrimaryAxis property, the chart will be changed to combination chart type.

### Step 4: Apply basic chart elements

Add the basic elements like chart title, data labels and legend.

• ChartTitle of chart object.
• Set DataLabels via DefaultDataPoints.
• Set TRUE to chart’s HasLegend property, to show the legend.

C#

```              //Apply chart elements
//Set Chart Title
chart.ChartTitle = "Combination Chart";

//Set Datalabels
serie1.DataPoints.DefaultDataPoint.DataLabels.IsValue = true;

//Set Legend
chart.HasLegend = true;
chart.Legend.Position = ExcelLegendPosition.Bottom;
```

## Applicable ExcelChartType enum types to create combination chart using XlsIO

Below is the list of ExcelChartType enum values can be applied to the series to create a combination chart.

### 1. Area

• Area
• Area_Stacked
• Area_Stacked_100

### 2. Bar

• Bar_Clustered
• Bar_Stacked
• Bar_Stacked_100

### 3. Column

• Column_Clustered
• Column_Stacked
• Column_Stacked_100

### 4. Line

• Line
• Line_Markers
• Line_Stacked
• Line_Stacked_100
• Line_Markers_Stacked
• Line_Markers_Stacked_100

• Pie
• PieOfPie
• Pie_Bar
• Doughnut

### 7. Scatter

• Scatter_Markers
• Scatter_Line
• Scatter_Line_Markers
• Scatter_SmoothedLine
• Scatter_SmoothedLine_Markers
Note:

1. Applying properties apart from the mentioned list might throw exception or the generate incorrect output document.
2. Combination_Chart type cannot be set to series type.

To know more about creating charts with various settings using Syncfusion Excel (XlsIO) library, please refer the documentation.

The following C#/ VB.NET complete code snippet shows the creation of combination of clustered column and line on secondary axis chart using XlsIO.

C#

```using Syncfusion.XlsIO;
using System.Reflection;
using System.IO;

namespace ChartSample
{
class Program
{
static void Main(string[] args)
{
using (ExcelEngine excelEngine = new ExcelEngine())
{
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2016;

//Open existing workbook with data entered
Assembly assembly = typeof(Program).GetTypeInfo().Assembly;
Stream fileStream = assembly.GetManifestResourceStream("ChartSample.InputTemplate.xlsx");
IWorkbook workbook = application.Workbooks.Open(fileStream);
IWorksheet worksheet = workbook.Worksheets[0];

//Initialize chart and assign data
chart.DataRange = worksheet["A1:C13"];

//Apply chart elements
//Set Chart Title
chart.ChartTitle = "Combination Chart";
chart.IsSeriesInRows = false;

//Set Legend
chart.HasLegend = true;
chart.Legend.Position = ExcelLegendPosition.Bottom;

//Set Serie type
IChartSerie serie1 = chart.Series[0];
IChartSerie serie2 = chart.Series[1];
serie1.SerieType = ExcelChartType.Column_Clustered;
serie2.SerieType = ExcelChartType.Line;
serie2.UsePrimaryAxis = false;

//set Data labels
serie1.DataPoints.DefaultDataPoint.DataLabels.IsValue = true;

//Positioning the chart in the worksheet
chart.TopRow = 8;
chart.LeftColumn = 1;
chart.BottomRow = 23;
chart.RightColumn = 8;

//Saving and closing the workbook
Stream stream = File.Create("Output.xlsx");
workbook.SaveAs(stream);
}
}
}
}

```

VB.NET

```Imports Syncfusion.XlsIO
Imports System.Reflection
Imports System.IO

Namespace ChartSample

Class Program

Public Shared Sub Main(ByVal args As String())
Using excelEngine As ExcelEngine = New ExcelEngine()
Dim application As IApplication = excelEngine.Excel
application.DefaultVersion = ExcelVersion.Excel2016

'Open existing workbook with data entered
Dim assembly As Assembly = GetType(Program).GetTypeInfo().Assembly
Dim fileStream As Stream = assembly.GetManifestResourceStream("ChartSample.InputTemplate.xlsx")
Dim workbook As IWorkbook = application.Workbooks.Open(fileStream)
Dim worksheet As IWorksheet = workbook.Worksheets(0)

'Initialize chart and assign data
Dim chart As IChartShape = worksheet.Charts.Add
chart.DataRange = worksheet("A1:C13")

'Apply chart elements
'Set Chart Title
chart.ChartTitle = "Combination Chart"
chart.IsSeriesInRows = False

'Set Legend
chart.HasLegend = True
chart.Legend.Position = ExcelLegendPosition.Bottom

'Set Serie type
Dim serie1 As IChartSerie = chart.Series(0)
Dim serie2 As IChartSerie = chart.Series(1)
serie1.SerieType = ExcelChartType.Column_Clustered
serie2.SerieType = ExcelChartType.Line
serie2.UsePrimaryAxis = False

'set Data labels
serie1.DataPoints.DefaultDataPoint.DataLabels.IsValue = True

'Positioning the chart in the worksheet
chart.TopRow = 8
chart.LeftColumn = 1
chart.BottomRow = 23
chart.RightColumn = 8

'Saving and closing the workbook
Dim stream As Stream = File.Create("Output.xlsx")
workbook.SaveAs(stream)
End Using
End Sub
End Class
End Namespace

```

2X faster development

The ultimate WinForms UI toolkit to boost your development speed.