Articles in this section
Category / Section

How to create bubble 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 bubble chart in Word document in C#.

What is a bubble chart?

A bubble chart represents data points with bubbles along with an additional dimension of the data, the size of bubbles. Just like a scatter chart, a bubble chart does not use a category axis. Both x (horizontal) and y (vertical) axes are value axes in addition with z (size) values.

Bubble chart

Bubble chart in Word document

Steps to create bubble 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.Bubble enum value.

C#

//Create and append the chart to the paragraph.
WChart chart = paragraph.AppendChart(446, 270);
//Set chart type.
chart.ChartType = OfficeChartType.Bubble;
  1. Assign data and chart elements.

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

  • ChartTitle of the chart object.
  • Set DataLabels using the DefaultDataPoint.
  • Add CategoryLabels and Values.
  • Set TRUE to the chart’s HasLegend property to show the legend, else False.

C#

//Apply the chart elements.
//Set a chart title.
chart.ChartTitle = "Bubble Chart";
 
//Set legend.
chart.HasLegend = false;
 
//Set Datalabels.
IOfficeChartSerie series = chart.Series.Add();
series.CategoryLabels = chart.ChartData[2, 1, 11, 1];
series.Values = chart.ChartData[2, 2, 11, 2];
series.Bubbles = chart.ChartData[2, 3, 11, 3];
series.DataPoints.DefaultDataPoint.DataLabels.IsValue = true;
series.DataPoints.DefaultDataPoint.DataLabels.Position = OfficeDataLabelPosition.Center;

Applicable properties for bubble chart

Below is a list of other common properties applicable for a bubble chart.

  • SizeRepresents
  • BubbleScale
  • ShowNegativeBubbles
    Note:

    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 bubble chart.

    Bubbles with negative size are said to be the negative bubbles.

The following C# code sample shows the creation of a bubble 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 type.
    chart.ChartType = OfficeChartType.Bubble;
    //Set chart data.
    chart.ChartData.SetValue(1, 1, "X-Values");
    chart.ChartData.SetValue(2, 1, -10);
    chart.ChartData.SetValue(3, 1, -20);
    chart.ChartData.SetValue(4, 1, -30);
    chart.ChartData.SetValue(5, 1, -40);
    chart.ChartData.SetValue(6, 1, -50);
    chart.ChartData.SetValue(7, 1, 10);
    chart.ChartData.SetValue(8, 1, 20);
    chart.ChartData.SetValue(9, 1, 30);
    chart.ChartData.SetValue(10, 1, 40);
    chart.ChartData.SetValue(11, 1, 50);
    chart.ChartData.SetValue(1, 2, "Y-Values");
    chart.ChartData.SetValue(2, 2, -100);
    chart.ChartData.SetValue(3, 2, -200);
    chart.ChartData.SetValue(4, 2, -300);
    chart.ChartData.SetValue(5, 2, -400);
    chart.ChartData.SetValue(6, 2, -500);
    chart.ChartData.SetValue(7, 2, 100);
    chart.ChartData.SetValue(8, 2, 200);
    chart.ChartData.SetValue(9, 2, 300);
    chart.ChartData.SetValue(10, 2, 400);
    chart.ChartData.SetValue(11, 2, 500);
    chart.ChartData.SetValue(1, 3, "Size");
    chart.ChartData.SetValue(2, 3, 1);
    chart.ChartData.SetValue(3, 3, -1);
    chart.ChartData.SetValue(4, 3, 1);
    chart.ChartData.SetValue(5, 3, -1);
    chart.ChartData.SetValue(6, 3, 1);
    chart.ChartData.SetValue(7, 3, -1);
    chart.ChartData.SetValue(8, 3, 1);
    chart.ChartData.SetValue(9, 3, -1);
    chart.ChartData.SetValue(10, 3, 1);
    chart.ChartData.SetValue(11, 3, -1);
    //Set a Chart Title.
    chart.ChartTitle = "Bubble Chart";
    //Set Datalabels.
    IOfficeChartSerie series = chart.Series.Add();
    //Set the data range of chart series – start row, start column, end row, and end column.
    series.CategoryLabels = chart.ChartData[2, 1, 11, 1];
    series.Values = chart.ChartData[2, 2, 11, 2];
    series.Bubbles = chart.ChartData[2, 3, 11, 3];
    series.DataPoints.DefaultDataPoint.DataLabels.IsValue = true;
    series.DataPoints.DefaultDataPoint.DataLabels.Position = OfficeDataLabelPosition.Center;
    //Set legend.
    chart.HasLegend = false;
    //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 bubble 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 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 stacked bar chart in Word document using C#?

How to create 3D 100% 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 area chart in Word document using C#?

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

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

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

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

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

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

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

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

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