HTML JPG PDF XML XLSX
  Product Family
XLSX

Create Combo Chart in XLSX Documents via C#

Generate sophisticated Excel XLSX worksheets with combined Line and Column chart types using server‑side .NET APIs.

Creating a Combo chart—a chart that combines two different chart types such as Column and Line—is straightforward with Aspose.Cells for .NET. This feature enables you to visualise data with mixed chart types without requiring Microsoft Office on the server.

How to create a Combo chart (Line + Column) via C#

A Combo chart helps you compare distinct data series that have different value ranges or units, making it ideal for business reporting, dashboards, and analytical applications.

Typical steps

  1. Include the required namespace.
  2. Create a Workbook instance.
  3. Populate worksheet cells with sample data.
  4. Add a chart of type ChartType.Column (the base chart).
  5. Convert the chart to a Combo chart.
  6. Add a Column series and a Line series.
  7. Set the secondary axis for the Line series (optional).
  8. Save the workbook as an XLSX file.

System Requirements

  • Windows, Linux or macOS with a supported .NET runtime (.NET Framework 4.6+, .NET Core 2.0+, .NET 5/6/7/8).
  • Visual Studio 2019/2022 or any other IDE that supports C# development.
  • Aspose.Cells for .NET library (installed via NuGet).

  • Install from command line: nuget install Aspose.Cells or via Package Manager Console: Install-Package Aspose.Cells.
  • Or download the full package from the Aspose.Cells .NET download page.
 

Create a Combo Chart (Line + Column) – C#

// ------------------------------------------------------------
//  Sample: Create a Combo chart (Column + Line) using Aspose.Cells for .NET
// ------------------------------------------------------------
using System;
using Aspose.Cells;
using Aspose.Cells.Charts;

namespace AsposeCellsComboChart
{
    class Program
    {
        static void Main()
        {
            // 1. Create a new workbook and obtain the first worksheet.
            var workbook = new Workbook();
            var sheet = workbook.Worksheets[0];

            // ------------------------------------------------------------
            // 2. Populate worksheet with sample data.
            // ------------------------------------------------------------
            //    A      B      C
            // 1  Month  Sales  Profit
            // 2  Jan    120    30
            // 3  Feb    150    45
            // 4  Mar    180    55
            // ------------------------------------------------------------
            sheet.Cells["A1"].Value = "Month";
            sheet.Cells["B1"].Value = "Sales";
            sheet.Cells["C1"].Value = "Profit";

            string[] months = { "Jan", "Feb", "Mar" };
            double[] sales = { 120, 150, 180 };
            double[] profit = { 30, 45, 55 };

            for (int i = 0; i < months.Length; i++)
            {
                sheet.Cells[i + 1, 0].Value = months[i];
                sheet.Cells[i + 1, 1].Value = sales[i];
                sheet.Cells[i + 1, 2].Value = profit[i];
            }

            // ------------------------------------------------------------
            // 3. Add a chart object – start with a Column chart (base type).
            // ------------------------------------------------------------
            int chartIndex = sheet.Charts.Add(ChartType.Column, 5, 0, 20, 10);
            Chart chart = sheet.Charts[chartIndex];
            chart.Title.Text = "Sales & Profit Combo Chart";

            // ------------------------------------------------------------
            // 4. Add Column series (primary axis) – Sales data.
            // ------------------------------------------------------------
            int salesSeriesIndex = chart.NSeries.Add("=Sheet1!$B$2:$B$4", true);
            chart.NSeries[salesSeriesIndex].Name = "Sales";
            chart.NSeries[salesSeriesIndex].Type = ChartType.Column; // Explicitly set Column type

            // ------------------------------------------------------------
            // 5. Add Line series (secondary axis) – Profit data.
            // ------------------------------------------------------------
            int profitSeriesIndex = chart.NSeries.Add("=Sheet1!$C$2:$C$4", true);
            chart.NSeries[profitSeriesIndex].Name = "Profit";
            chart.NSeries[profitSeriesIndex].Type = ChartType.Line; // Line for secondary series

            // Place the line series on the secondary axis (optional but common).
            chart.NSeries[profitSeriesIndex].PlotOnSecondAxis = true;

            // ------------------------------------------------------------
            // 6. Customize axes titles (optional).
            // ------------------------------------------------------------
            chart.CategoryAxis.Title.Text = "Month";
            chart.ValueAxis.Title.Text = "Sales";
            chart.ValueAxisSecondary.Title.Text = "Profit";

            // ------------------------------------------------------------
            // 7. Save the workbook.
            // ------------------------------------------------------------
            workbook.Save("ComboChart_Output.xlsx");
        }
    }
}
 
Aspose.Cells for .NET is a powerful spreadsheet processing library that enables developers to create, modify, convert, render, and print Excel files across platforms without requiring Microsoft Office. Its rich API covers a wide range of charting scenarios, including Combo charts that combine multiple chart types in a single view.

XLSX What is XLSX File Format?

XLSX, introduced with Microsoft Office 2007, is an Open XML based format that stores spreadsheet data, styles, and charts in a zip package containing XML parts. Aspose.Cells works directly with this format, allowing you to manipulate charts without extracting the package manually.

Read More