Articles in this section
Category / Section

How to change scatter chart marker color for each data points in Word document?

4 mins read

Syncfusion Essential DocIO is a .NET Word library used to create, read, and edit Word documents programmatically without Microsoft Word or Interop dependencies. Using this library, you can change the scatter chart marker color for each data points in Word document.

Steps to change the scatter chart marker color for each data points in Word document programmatically:

  1. Create a new C# console application project.

    Create new c# console app

  2. Install the Syncfusion.DocIO.Winforms NuGet package as a reference to your .NET Framework applications from NuGet.org.

    Install WinForms NuGet packages

  3. Include the following namespace in the Program.cs file.

C#

using System.Drawing;
using Syncfusion.DocIO;
using Syncfusion.DocIO.DLS;
using Syncfusion.OfficeChart;

 

VB.NET

Imports System.Drawing
Imports Syncfusion.DocIO
Imports Syncfusion.DocIO.DLS
Imports Syncfusion.OfficeChart

 

  1. Use the following code example to change the scatter chart marker color for each data points in Word document.

C#

//Creates a new Word document
WordDocument document = new WordDocument();
//Adds section to the document
IWSection sec = document.AddSection();
//Adds paragraph to the section
IWParagraph paragraph = sec.AddParagraph();
//Creates and Appends chart to the paragraph
WChart chart = paragraph.AppendChart(446, 270);
//Sets chart data - Row1
chart.ChartData.SetValue(1, 2, "Higest Price");
chart.ChartData.SetValue(1, 3, "Average Price");
chart.ChartData.SetValue(1, 4, "Lowest Price");
//Sets chart data - Row2
chart.ChartData.SetValue(2, 1, "BT");
chart.ChartData.SetValue(2, 2, 65);
chart.ChartData.SetValue(2, 3, 57.50);
chart.ChartData.SetValue(2, 4, 50);
//Sets chart data - Row3
chart.ChartData.SetValue(3, 1, "Carphone");
chart.ChartData.SetValue(3, 2, 69);
chart.ChartData.SetValue(3, 3, 46.48);
chart.ChartData.SetValue(3, 4, 30);
//Sets chart data - Row4
chart.ChartData.SetValue(4, 1, "EE");
chart.ChartData.SetValue(4, 2, 74);
chart.ChartData.SetValue(4, 3, 62.33);
chart.ChartData.SetValue(4, 4, 49);
//Sets chart data - Row5
chart.ChartData.SetValue(5, 1, "O2");
chart.ChartData.SetValue(5, 2, 67.25);
chart.ChartData.SetValue(5, 3, 52.64);
chart.ChartData.SetValue(5, 4, 40.56);
//Sets chart data - Row6
chart.ChartData.SetValue(6, 1, "Sky Mobile");
chart.ChartData.SetValue(6, 2, 85);
chart.ChartData.SetValue(6, 3, 60.20);
chart.ChartData.SetValue(6, 4, 38);
//Sets chart data - Row7
chart.ChartData.SetValue(7, 1, "Three");
chart.ChartData.SetValue(7, 2, 56);
chart.ChartData.SetValue(7, 3, 45);
chart.ChartData.SetValue(7, 4, 30);
//Sets chart data - Row8
chart.ChartData.SetValue(8, 1, "Vodafone");
chart.ChartData.SetValue(8, 2, 73);
chart.ChartData.SetValue(8, 3, 61);
chart.ChartData.SetValue(8, 4, 48);
//Creates a new chart series with the name
IOfficeChartSerie seriesHP = chart.Series.Add("Higest Price");
//Sets the data range of chart series – start row, start column, end row, end column
seriesHP.Values = chart.ChartData[2, 2, 8, 2];
//Creates a new chart series with the name
IOfficeChartSerie seriesAP = chart.Series.Add("Average Price");
//Sets the data range of chart series – start row, start column, end row, end column
seriesAP.Values = chart.ChartData[2, 3, 8, 3];
//Creates a new chart series with the name
IOfficeChartSerie seriesLP = chart.Series.Add("Lowest Price");
//Sets the data range of chart series – start row, start column, end row, end column
seriesLP.Values = chart.ChartData[2, 4, 8, 4];
//Specifies the chart title
chart.ChartTitle = "Headline MLR";
//Sets the data range of the category axis
chart.PrimaryCategoryAxis.CategoryLabels = chart.ChartData[2, 1, 8, 1];
chart.Legend.Position = OfficeLegendPosition.Top;
//Specifies the chart type
chart.ChartType = OfficeChartType.Scatter_Markers;
//Changes the marker style for series
chart.Series[1].SerieFormat.MarkerStyle = OfficeChartMarkerType.Circle;
chart.Series[1].SerieFormat.MarkerSize = 20;
//Displays the data label values of chart series
chart.Series[0].DataPoints.DefaultDataPoint.DataLabels.IsValue = true;
chart.Series[1].DataPoints.DefaultDataPoint.DataLabels.IsValue = true;
chart.Series[2].DataPoints.DefaultDataPoint.DataLabels.IsValue = true;
//Set a first marker color as Purple.
chart.Series[1].DataPoints[0].IsDefaultmarkertype = true;
chart.Series[1].DataPoints[0].DataFormat.MarkerBackgroundColor = Color.Purple;
//Set a second marker color as Black.
chart.Series[1].DataPoints[1].IsDefaultmarkertype = true;
chart.Series[1].DataPoints[1].DataFormat.MarkerBackgroundColor = Color.Black;
//Set a third marker color as Green.
chart.Series[1].DataPoints[2].IsDefaultmarkertype = true;
chart.Series[1].DataPoints[2].DataFormat.MarkerBackgroundColor = Color.Green;
//Set a fourth marker color as Blue.
chart.Series[1].DataPoints[3].IsDefaultmarkertype = true;
chart.Series[1].DataPoints[3].DataFormat.MarkerBackgroundColor = Color.Blue;
//Set a fifth marker color as SkyBlue.
chart.Series[1].DataPoints[4].IsDefaultmarkertype = true;
chart.Series[1].DataPoints[4].DataFormat.MarkerBackgroundColor = Color.SkyBlue;
//Set a sixth marker color as Brown.
chart.Series[1].DataPoints[5].IsDefaultmarkertype = true;
chart.Series[1].DataPoints[5].DataFormat.MarkerBackgroundColor = Color.Brown;
//Set a seventh marker color as Red.
chart.Series[1].DataPoints[6].IsDefaultmarkertype = true;
chart.Series[1].DataPoints[6].DataFormat.MarkerBackgroundColor = Color.Red;
//Saves the document
document.Save("Output.docx", FormatType.Docx);
//Closes the document
document.Close();

 

VB.NET

'Creates a New Word document
Dim document As WordDocument = New WordDocument()
'Adds section to the document
Dim sec As IWSection = document.AddSection()
'Adds paragraph to the section
Dim paragraph As IWParagraph = sec.AddParagraph()
'Creates and Appends chart to the paragraph
Dim chart As WChart = paragraph.AppendChart(446, 270)
'Sets chart data - Row1
chart.ChartData.SetValue(1, 2, "Higest Price")
chart.ChartData.SetValue(1, 3, "Average Price")
chart.ChartData.SetValue(1, 4, "Lowest Price")
'Sets chart data - Row2
chart.ChartData.SetValue(2, 1, "BT")
chart.ChartData.SetValue(2, 2, 65)
chart.ChartData.SetValue(2, 3, 57.5)
chart.ChartData.SetValue(2, 4, 50)
'Sets chart data - Row3
chart.ChartData.SetValue(3, 1, "Carphone")
chart.ChartData.SetValue(3, 2, 69)
chart.ChartData.SetValue(3, 3, 46.48)
chart.ChartData.SetValue(3, 4, 30)
'Sets chart data - Row4
chart.ChartData.SetValue(4, 1, "EE")
chart.ChartData.SetValue(4, 2, 74)
chart.ChartData.SetValue(4, 3, 62.33)
chart.ChartData.SetValue(4, 4, 49)
'Sets chart data - Row5
chart.ChartData.SetValue(5, 1, "O2")
chart.ChartData.SetValue(5, 2, 67.25)
chart.ChartData.SetValue(5, 3, 52.64)
chart.ChartData.SetValue(5, 4, 40.56)
'Sets chart data - Row6
chart.ChartData.SetValue(6, 1, "Sky Mobile")
chart.ChartData.SetValue(6, 2, 85)
chart.ChartData.SetValue(6, 3, 60.2)
chart.ChartData.SetValue(6, 4, 38)
'Sets chart data - Row7
chart.ChartData.SetValue(7, 1, "Three")
chart.ChartData.SetValue(7, 2, 56)
chart.ChartData.SetValue(7, 3, 45)
chart.ChartData.SetValue(7, 4, 30)
'Sets chart data - Row8
chart.ChartData.SetValue(8, 1, "Vodafone")
chart.ChartData.SetValue(8, 2, 73)
chart.ChartData.SetValue(8, 3, 61)
chart.ChartData.SetValue(8, 4, 48)
'Creates a new chart series with the name
Dim seriesHP As IOfficeChartSerie = chart.Series.Add("Higest Price")
'Sets the data range of chart series – start row, start column, end row, end column
seriesHP.Values = chart.ChartData(2, 2, 8, 2)
'Creates a new chart series with the name
Dim seriesAP As IOfficeChartSerie = chart.Series.Add("Average Price")
'Sets the data range of chart series – start row, start column, end row, end column
seriesAP.Values = chart.ChartData(2, 3, 8, 3)
'Creates a new chart series with the name
Dim seriesLP As IOfficeChartSerie = chart.Series.Add("Lowest Price")
'Sets the data range of chart series – start row, start column, end row, end column
seriesLP.Values = chart.ChartData(2, 4, 8, 4)
'Specifies the chart title
chart.ChartTitle = "Headline MLR"
'Sets the data range of the category axis
chart.PrimaryCategoryAxis.CategoryLabels = chart.ChartData(2, 1, 8, 1)
chart.Legend.Position = OfficeLegendPosition.Top
'Specifies the chart type
chart.ChartType = OfficeChartType.Scatter_Markers
'Changes the marker style for series
chart.Series(1).SerieFormat.MarkerStyle = OfficeChartMarkerType.Circle
chart.Series(1).SerieFormat.MarkerSize = 20
'Displays the data label values of chart series
chart.Series(0).DataPoints.DefaultDataPoInteger.DataLabels.IsValue = True
chart.Series(1).DataPoints.DefaultDataPoInteger.DataLabels.IsValue = True
chart.Series(2).DataPoints.DefaultDataPoInteger.DataLabels.IsValue = True
'Set a first marker color as Purple.
chart.Series(1).DataPoints(0).IsDefaultmarkertype = True
chart.Series(1).DataPoints(0).DataFormat.MarkerBackgroundColor = Color.Purple
'Set a second marker color as Black.
chart.Series(1).DataPoints(1).IsDefaultmarkertype = True
chart.Series(1).DataPoints(1).DataFormat.MarkerBackgroundColor = Color.Black
'Set a third marker color as Green.
chart.Series(1).DataPoints(2).IsDefaultmarkertype = True
chart.Series(1).DataPoints(2).DataFormat.MarkerBackgroundColor = Color.Green
'Set a fourth marker color as Blue.
chart.Series(1).DataPoints(3).IsDefaultmarkertype = True
chart.Series(1).DataPoints(3).DataFormat.MarkerBackgroundColor = Color.Blue
'Set a fifth marker color as SkyBlue.
chart.Series(1).DataPoints(4).IsDefaultmarkertype = True
chart.Series(1).DataPoints(4).DataFormat.MarkerBackgroundColor = Color.SkyBlue
'Set a sixth marker color as Brown.
chart.Series(1).DataPoints(5).IsDefaultmarkertype = True
chart.Series(1).DataPoints(5).DataFormat.MarkerBackgroundColor = Color.Brown
'Set a seventh marker color as Red.
chart.Series(1).DataPoints(6).IsDefaultmarkertype = True
chart.Series(1).DataPoints(6).DataFormat.MarkerBackgroundColor = Color.Red
'Saves the document
document.Save("Output.docx", FormatType.Docx)
'Closes the document
document.Close()

 

A complete working sample to change the scatter chart marker color for each data points in Word document using C# can be downloaded from here

Take a moment to peruse the document where you can find basic Word document processing options along with the features like mail merge, merge 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.

Note:

Starting with v16.2.0.x, if you reference Syncfusion assemblies from trial setup or from the NuGet feed, include a license key in your projects. Refer to the link to learn about how to generate and register a Syncfusion license key in your application to use the components without a trail message.

 

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