Articles in this section

How to change scatter chart marker color for each data in WinForms Presentation?

 The PowerPoint framework is a feature rich  .NET PowerPoint class library  that can be used by developers to create, read, edit and convert PowerPoint files to PDFs and images programmatically without Office or interop dependencies.

 Steps to change scatter chart marker color for each data points in Presentation:

  1. Create a new C# console application project.

Create a new console app

 

  1. Install the Syncfusion.Presentation.WinForms NuGet package as a reference to your .NET Framework applications from NuGet.org

Install NuGet package

 

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

C#

using Syncfusion.Presentation;
using Syncfusion.OfficeChart;
using System.Drawing;

 

VB

Imports Syncfusion.Presentation
Imports Syncfusion.OfficeChart
Imports System.Drawing

 

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

C#

//Creates a Presentation instance
IPresentation pptDoc = Presentation.Create();
//Adds a blank slide to the Presentation
ISlide slide = pptDoc.Slides.Add(SlideLayoutType.Blank);
//Adds chart to the slide with position and size
IPresentationChart chart = slide.Charts.AddChart(50, 50, 800, 400); 
//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;
pptDoc.Save("Output.pptx");
pptDoc.Dispose();

 

VB

'Creates a Presentation instance
Dim pptDoc As IPresentation = Presentation.Create()
'Adds a blank slide to the Presentation
Dim slide As ISlide = pptDoc.Slides.Add(SlideLayoutType.Blank)
'Adds chart to the slide with position and size
Dim chart As IPresentationChart = slide.Charts.AddChart(50, 50, 800, 400)
'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.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 Green.
chart.Series(1).DataPoints(3).IsDefaultmarkertype = True
chart.Series(1).DataPoints(3).DataFormat.MarkerBackgroundColor = Color.Blue
'Set a fifth marker color as Green.
chart.Series(1).DataPoints(4).IsDefaultmarkertype = True
chart.Series(1).DataPoints(4).DataFormat.MarkerBackgroundColor = Color.SkyBlue
'Set a sixth marker color as Green.
chart.Series(1).DataPoints(5).IsDefaultmarkertype = True
chart.Series(1).DataPoints(5).DataFormat.MarkerBackgroundColor = Color.Brown
'Set a seventh marker color as Green.
chart.Series(1).DataPoints(6).IsDefaultmarkertype = True
chart.Series(1).DataPoints(6).DataFormat.MarkerBackgroundColor = Color.Red
pptDoc.Save("Output.pptx")
pptDoc.Dispose()

 

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

 

By executing the program, you will get the output Word document as follows.

Table

Description automatically generated

 

Explore more about the rich set of Syncfusion® PowerPoint 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 generating and registering a Syncfusion® license key in your application to use the components without trail message.

 

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