Articles in this section
Category / Section

How to create combination chart in Word document using C#?

4 mins read

Syncfusion Essential DocIO is a .NET Core Word library used to create, read, and edit Word documents programmatically without Microsoft Word or Interop dependencies. Using this library, you can create combination chart in Word document in C#.

What is a combination cone chart?

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

Combination chart in .NET Core Word library

Combination chart in Word document

Steps to create combination chart in Word document:

  1. Initialize chart.

Create a chart object by calling the paragraph.AppendChart(446,270) method and specify the chart type to the OfficeChartType.Combination_Chart enum value.

C#

//Create and append the chart to the paragraph.
WChart chart = paragraph.AppendChart(446, 270);
//Set chart type.
chart.ChartType = OfficeChartType.Combination_Chart;
  1. 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.
series1.SerieType = OfficeChartType.Column_Clustered;
series2.SerieType = OfficeChartType.Line;
series2.UsePrimaryAxis = false;
  1. Assign data and chart elements.

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

  • Assign data.
  • ChartTitle of the chart object.
  • Set DataLabels using the DefaultDataPoint.
  • Set TRUE to the chart’s HasLegend property to show the legend, else False.

C#

//Set region of Chart data.
chart.DataRange = chart.ChartData[1, 1, 6, 4];
 
//Apply the chart elements.
//Set a chart title.
chart.ChartTitle = "Combination Chart";
 
//Set Datalabels.
series1.DataPoints.DefaultDataPoint.DataLabels.IsValue = true;
 
//Set legend.
chart.HasLegend = true;
chart.Legend.Position = OfficeLegendPosition.Bottom;

Applicable OfficeChartType enum types to create combination chart using DocIO

Below is a list of OfficeChartType enum values that 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_Markes_Stacked_100

5. Pie

  • Pie
  • PieOfPie
  • Pie_Bar
  • Doughnut

6. Radar

  • Radar
  • Radar_Markers
  • Radar_Filled

7. Scatter

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

    1. Applying the properties apart from the mentioned list might throw an exception, or the changes will not be reflected in the output document because those properties are not related to the combination chart.

    2. Combination_Chart type cannot be set to series type

The following C# code sample shows the creation of combination chart using the Word library.

C#

//Create a new Word document.
using (WordDocument document = new WordDocument())
{
    //Add a section to the document.
    IWSection section = document.AddSection();
    //Add a paragraph to the section.
    IWParagraph paragraph = section.AddParagraph();
    //Create and append the chart to the paragraph.
    WChart chart = paragraph.AppendChart(446, 270);
    //Set chart data.
    chart.ChartData.SetValue(1, 1, "Month");
    chart.ChartData.SetValue(2, 1, "Jan");
    chart.ChartData.SetValue(3, 1, "Feb");
    chart.ChartData.SetValue(4, 1, "Mar");
    chart.ChartData.SetValue(5, 1, "Apr");
    chart.ChartData.SetValue(6, 1, "May");
    chart.ChartData.SetValue(7, 1, "Jun");
    chart.ChartData.SetValue(8, 1, "Jul");
    chart.ChartData.SetValue(9, 1, "Aug");
    chart.ChartData.SetValue(10, 1, "Sep");
    chart.ChartData.SetValue(11, 1, "Oct");
    chart.ChartData.SetValue(12, 1, "Nov");
    chart.ChartData.SetValue(13, 1, "Dec");
    chart.ChartData.SetValue(1, 2, "Rainy Days");
    chart.ChartData.SetValue(2, 2, 12);
    chart.ChartData.SetValue(3, 2, 11);
    chart.ChartData.SetValue(4, 2, 10);
    chart.ChartData.SetValue(5, 2, 9);
    chart.ChartData.SetValue(6, 2, 8);
    chart.ChartData.SetValue(7, 2, 6);
    chart.ChartData.SetValue(8, 2, 4);
    chart.ChartData.SetValue(9, 2, 6);
    chart.ChartData.SetValue(10, 2, 7);
    chart.ChartData.SetValue(11, 2, 8);
    chart.ChartData.SetValue(12, 2, 10);
    chart.ChartData.SetValue(13, 2, 11);
    chart.ChartData.SetValue(1, 3, "Profit");
    chart.ChartData.SetValue(2, 3, 3574);
    chart.ChartData.SetValue(3, 3, 4708);
    chart.ChartData.SetValue(4, 3, 5332);
    chart.ChartData.SetValue(5, 3, 6693);
    chart.ChartData.SetValue(6, 3, 8843);
    chart.ChartData.SetValue(7, 3, 12347);
    chart.ChartData.SetValue(8, 3, 15180);
    chart.ChartData.SetValue(9, 3, 11198);
    chart.ChartData.SetValue(10, 3, 9739);
    chart.ChartData.SetValue(11, 3, 9846);
    chart.ChartData.SetValue(12, 3, 6620);
    chart.ChartData.SetValue(13, 3, 5085);
    //Set region of Chart data.
    chart.DataRange = chart.ChartData[1, 1, 13, 3];
    //Set chart series in the column for assigned data region.
    chart.IsSeriesInRows = false;
    //Set a Chart Title.
    chart.ChartTitle = "Combination Chart";
    //Set Datalabels.
    IOfficeChartSerie series1 = chart.Series[0];
    IOfficeChartSerie series2 = chart.Series[1];
    //Set Serie type.
    series1.SerieType = OfficeChartType.Column_Clustered;
    series2.SerieType = OfficeChartType.Line;
    series2.UsePrimaryAxis = false;
    //Set Datalabels.
    series1.DataPoints.DefaultDataPoint.DataLabels.IsValue = true;
    //Set legend.
    chart.HasLegend = true;
    chart.Legend.Position = OfficeLegendPosition.Bottom;
    //Set chart type.
    chart.ChartType = OfficeChartType.Combination_Chart;
    //Create a file stream.
    using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"../../../Sample.docx"), FileMode.Create, FileAccess.ReadWrite))
    {
        //Save the Word document to the file stream.
        document.Save(outputFileStream, FormatType.Docx)
    }
}

A complete working sample of how to create combination chart in Word document in C# can be downloaded from GitHub.

Take a moment to peruse the documentation, where you can find basic Word document processing options along with the features like mail mergemerge and split documents, find and replace text in the Word document, protect the Word documents, and most importantly, the PDF and Image conversions with code examples.

Explore more about the rich set of Syncfusion Word Framework features and an online example to create a chart in a Word document.

See Also:

How to create clustered column chart in Word document using C# and VB.NET

How to create stacked column chart in Word document using C#?

How to create 3D column chart in Word document using C#?

How to create clustered bar chart in Word document using C#?

How to create stacked bar chart in Word document using C#?

How to create 3D clustered bar chart in Word document using C#?

How to create 100% stacked bar chart in Word document using C#?

How to create 3D area chart in Word document using C#?

Conclusion

I hope you enjoyed learning about how to create combination chart in Word document using C#.

You can refer to our .NET Core Word library’s feature tour page to know about its other groundbreaking feature representations. You can also explore our .NET Core Word library example to understand how to present and manipulate data. 

For current customers, you can check out our .NET Core components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our .NET Core Word library and other .NET Core components.

If you have any queries or require clarifications, please let us know in comments below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!

 

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied