Request for Sample Code to Create a Combined Column Chart using Aspose cells

Hi Team,
We have attempted to create a column bar chart using Aspose. Cells but are looking to achieve a Combined Column Chart instead. Could you please provide a sample code in C# for creating a Combined Column Chart using Aspose?Cells?

For reference, I have attached a screenshot illustrating the desired output. Please let us know if you need additional details.

Looking forward to your assistance.
ColumnChart.zip (10.1 KB)

@sanjai03

To create a Combined Column Chart using Aspose.Cells in C#, you can follow the sample code provided below. This code demonstrates how to set up a workbook, add data, and create a combined chart with different series types.

// Create a new workbook
Workbook workbook = new Workbook();
// Access the first worksheet in the workbook
Worksheet worksheet = workbook.Worksheets[0];

// Define your data
object[,] data = new object[,] {
    { "Category", "S-55", "S-65", "S-70", "S-Column" },
    { "0%", 55, 10, 5, 0.12 },
    { "25%", 55, 10, 5, 0.12 },
    { "50%", 55, 10, 5, 0.4 },
    { "75%", 70.00, 5, 2.5, 0.38 },
    { "100%", 85, 0, 0, 0.01 }
};

// Get the range of cells where you want to set values
int startRow = 0;
int startColumn = 0;
int numRows = data.GetLength(0);
int numCols = data.GetLength(1);
var range = worksheet.Cells.CreateRange(startRow, startColumn, numRows, numCols);

// Set values from the array to the range
range.Value = data;

// Adding a chart to the worksheet
int chartIndex = worksheet.Charts.Add(Aspose.Cells.Charts.ChartType.AreaStacked, 6, 0, 25, 10);
// Accessing the instance of the newly added chart
Aspose.Cells.Charts.Chart chart = worksheet.Charts[chartIndex];

// Adding NSeries (chart data source) to the chart
var series1 = chart.NSeries[chart.NSeries.Add("Sheet1!B2:B6", true)];
var series2 = chart.NSeries[chart.NSeries.Add("Sheet1!C2:C6", true)];
var series3 = chart.NSeries[chart.NSeries.Add("Sheet1!D2:D6", true)];
var series4 = chart.NSeries[chart.NSeries.Add("Sheet1!E2:E6", true)];

// Set the chart types for each series
chart.NSeries[0].Type = Aspose.Cells.Charts.ChartType.Column;
chart.NSeries[1].Type = Aspose.Cells.Charts.ChartType.LineStackedWithDataMarkers;
series1.Type = Aspose.Cells.Charts.ChartType.AreaStacked;
series2.Type = Aspose.Cells.Charts.ChartType.AreaStacked;
series3.Type = Aspose.Cells.Charts.ChartType.AreaStacked;
series4.Type = Aspose.Cells.Charts.ChartType.ColumnStacked;

// Set the category data
chart.NSeries.CategoryData = "A2:A6";
series1.Name = "S-55";
series2.Name = "S-65";
series3.Name = "S-70";
series4.Name = "S-Column";

// Save the workbook
workbook.Save("output.xlsx");

This code initializes a new workbook, populates it with data, and creates a combined chart with both column and line series. You can adjust the data and chart types as needed to match your specific requirements.

If you have any further questions or need additional modifications, feel free to ask!

@sanjai03
Please plot the second series to secondary axis:

     // Create a new workbook
            Workbook workbook = new Workbook();
            // Access the first worksheet in the workbook
            Worksheet worksheet = workbook.Worksheets[0];

            // Define your data
            object[,] data = new object[,] {
    { "Category", "S-55", "S-65", "S-70", "S-Column" },
    { "0%", 55, 10, 5, 0.12 },
    { "25%", 55, 10, 5, 0.12 }
};

            // Get the range of cells where you want to set values
            int startRow = 0;
            int startColumn = 0;
            int numRows = data.GetLength(0);
            int numCols = data.GetLength(1);
            var range = worksheet.Cells.CreateRange(startRow, startColumn, numRows, numCols);

            // Set values from the array to the range
            range.Value = data;

            // Adding a chart to the worksheet
            int chartIndex = worksheet.Charts.Add(Aspose.Cells.Charts.ChartType.ColumnStacked, 6, 0, 25, 10);
            // Accessing the instance of the newly added chart
            Aspose.Cells.Charts.Chart chart = worksheet.Charts[chartIndex];

            chart.SetChartDataRange("A1:C3", true);
            chart.NSeries[1].PlotOnSecondAxis = true;
            // Save the workbook
            workbook.Save(dir + "dest.xlsx");