Scatter in Blazor Charts Component
18 Sep 202423 minutes to read
Scatter
Scatter Chart is used to visualize the relationship between two Cartesian parameters. To render a scatter series in your chart, define the series Type
as Scatter
in your chart configuration. This indicates that the data should be displayed as individual points scattered across the chart.
@using Syncfusion.Blazor.Charts
<SfChart DataSource="@ChartDataList">
<ChartPrimaryXAxis ValueType="Syncfusion.Blazor.Charts.ValueType.Category"></ChartPrimaryXAxis>
<ChartSeriesCollection>
<ChartSeries XName="X" YName="YValue" Type="ChartSeriesType.Scatter">
</ChartSeries>
<ChartSeries XName="X" YName="YValue1" Type="ChartSeriesType.Scatter">
</ChartSeries>
</ChartSeriesCollection>
</SfChart>
@code{
public class ChartData
{
public string X { get; set; }
public double YValue { get; set; }
public double YValue1 { get; set; }
}
public List<ChartData> ChartDataList = new List<ChartData>
{
new ChartData { X= "USA", YValue= 46, YValue1=56 },
new ChartData { X= "GBR", YValue= 27, YValue1=17 },
new ChartData { X= "CHN", YValue= 26, YValue1=36 },
new ChartData { X= "UK", YValue= 56, YValue1=16 },
new ChartData { X= "AUS", YValue= 12, YValue1=46 },
new ChartData { X= "IND", YValue= 26, YValue1=16 },
new ChartData { X= "DEN", YValue= 26, YValue1=12 },
new ChartData { X= "MEX", YValue= 34, YValue1=32},
};
}
NOTE
Refer to our Blazor Scatter Chart feature tour page to know about its other groundbreaking feature representations. Explore our Blazor Scatter Chart Example to know how to plot data with two numeric parameters.
Binding data with series
You can bind data to the chart using the DataSource
property within the series configuration. The DataSource
value can be set using either SfDataManager
property values or a list of business objects. More information on data binding can be found here. To display the data correctly, map the fields from the data to the chart series’ XName
and YName
properties.
@using Syncfusion.Blazor.Charts
<SfChart DataSource="@ChartDataList">
<ChartPrimaryXAxis ValueType="Syncfusion.Blazor.Charts.ValueType.Category"></ChartPrimaryXAxis>
<ChartSeriesCollection>
<ChartSeries XName="X" YName="YValue" Type="ChartSeriesType.Scatter">
</ChartSeries>
<ChartSeries XName="X" YName="YValue1" Type="ChartSeriesType.Scatter">
</ChartSeries>
</ChartSeriesCollection>
</SfChart>
@code{
public class ChartData
{
public string X { get; set; }
public double YValue { get; set; }
public double YValue1 { get; set; }
}
public List<ChartData> ChartDataList = new List<ChartData>
{
new ChartData { X= "USA", YValue= 46, YValue1=56 },
new ChartData { X= "GBR", YValue= 27, YValue1=17 },
new ChartData { X= "CHN", YValue= 26, YValue1=36 },
new ChartData { X= "UK", YValue= 56, YValue1=16 },
new ChartData { X= "AUS", YValue= 12, YValue1=46 },
new ChartData { X= "IND", YValue= 26, YValue1=16 },
new ChartData { X= "DEN", YValue= 26, YValue1=12 },
new ChartData { X= "MEX", YValue= 34, YValue1=32},
};
}
Series customization
The following properties can be used to customize the Scatter series.
Fill
The Fill property determines the color applied to the series.
@using Syncfusion.Blazor.Charts
<SfChart>
<ChartPrimaryXAxis ValueType="Syncfusion.Blazor.Charts.ValueType.Category"></ChartPrimaryXAxis>
<ChartSeriesCollection>
<ChartSeries DataSource="@ChartDataList" XName="X" YName="YValue" Fill="green" Type="Syncfusion.Blazor.Charts.ChartSeriesType.Scatter">
</ChartSeries>
<ChartSeries DataSource="@ChartDataList" XName="X" YName="YValue1" Fill="blue" Type="Syncfusion.Blazor.Charts.ChartSeriesType.Scatter">
</ChartSeries>
</ChartSeriesCollection>
</SfChart>
@code {
public class ChartData
{
public string X { get; set; }
public double YValue { get; set; }
public double YValue1 { get; set; }
}
public List<ChartData> ChartDataList = new List<ChartData>
{
new ChartData { X= "USA", YValue= 46, YValue1=56 },
new ChartData { X= "GBR", YValue= 27, YValue1=17 },
new ChartData { X= "CHN", YValue= 26, YValue1=36 },
new ChartData { X= "UK", YValue= 56, YValue1=16 },
new ChartData { X= "AUS", YValue= 12, YValue1=46 },
new ChartData { X= "IND", YValue= 26, YValue1=16 },
new ChartData { X= "DEN", YValue= 26, YValue1=12 },
new ChartData { X= "MEX", YValue= 34, YValue1=32},
};
}
The Fill property can be used to apply a gradient color to the scatter series. By configuring this property with gradient values, you can create a visually appealing effect in which the color transitions smoothly from one shade to another.
@using Syncfusion.Blazor.Charts
<SfChart>
<ChartPrimaryXAxis ValueType="Syncfusion.Blazor.Charts.ValueType.Category"></ChartPrimaryXAxis>
<ChartSeriesCollection>
<ChartSeries DataSource="@ChartDataList" XName="X" YName="YValue" Fill="url(#grad1)" Type="Syncfusion.Blazor.Charts.ChartSeriesType.Scatter">
<ChartMarker Height="10" Width="10" />
</ChartSeries>
<ChartSeries DataSource="@ChartDataList" XName="X" YName="YValue1" Fill="url(#grad2)" Type="Syncfusion.Blazor.Charts.ChartSeriesType.Scatter">
<ChartMarker Height="10" Width="10" />
</ChartSeries>
</ChartSeriesCollection>
</SfChart>
<svg style="height: 0">
<defs>
<linearGradient id="grad1" x1="0%" y1="0%" x2="0%" y2="100%">
<stop offset="20%" style="stop-color:orange;stop-opacity:1" />
<stop offset="100%" style="stop-color:black;stop-opacity:1" />
</linearGradient>
</defs>
</svg>
<svg style="height: 0">
<defs>
<linearGradient id="grad2" x1="0%" y1="0%" x2="0%" y2="100%">
<stop offset="20%" style="stop-color:blue;stop-opacity:1" />
<stop offset="100%" style="stop-color:black;stop-opacity:1" />
</linearGradient>
</defs>
</svg>
@code {
public class ChartData
{
public string X { get; set; }
public double YValue { get; set; }
public double YValue1 { get; set; }
}
public List<ChartData> ChartDataList = new List<ChartData>
{
new ChartData { X= "USA", YValue= 46, YValue1=56 },
new ChartData { X= "GBR", YValue= 27, YValue1=17 },
new ChartData { X= "CHN", YValue= 26, YValue1=36 },
new ChartData { X= "UK", YValue= 56, YValue1=16 },
new ChartData { X= "AUS", YValue= 12, YValue1=46 },
new ChartData { X= "IND", YValue= 26, YValue1=16 },
new ChartData { X= "DEN", YValue= 26, YValue1=12 },
new ChartData { X= "MEX", YValue= 34, YValue1=32},
};
}
Opacity
The Opacity property specifies the transparency level of the Fill. Adjusting this property allows you to control how opaque or transparent the fill color of the series appears.
@using Syncfusion.Blazor.Charts
<SfChart DataSource="@ChartDataList">
<ChartPrimaryXAxis ValueType="Syncfusion.Blazor.Charts.ValueType.Category"></ChartPrimaryXAxis>
<ChartSeriesCollection>
<ChartSeries XName="X" YName="YValue" Type="ChartSeriesType.Scatter" Fill="blue" Opacity="0.5">
<ChartMarker Height="10" Width="10" Shape="ChartShape.Circle">
</ChartMarker>
</ChartSeries>
<ChartSeries XName="X" YName="YValue1" Type="ChartSeriesType.Scatter" Fill="red" Opacity="0.5">
<ChartMarker Height="10" Width="10" Shape="ChartShape.Diamond">
</ChartMarker>
</ChartSeries>
</ChartSeriesCollection>
</SfChart>
@code{
public class ChartData
{
public string X { get; set; }
public double YValue { get; set; }
public double YValue1 { get; set; }
}
public List<ChartData> ChartDataList = new List<ChartData>
{
new ChartData { X= "USA", YValue= 46, YValue1=56 },
new ChartData { X= "GBR", YValue= 27, YValue1=17 },
new ChartData { X= "CHN", YValue= 26, YValue1=36 },
new ChartData { X= "UK", YValue= 56, YValue1=16 },
new ChartData { X= "AUS", YValue= 12, YValue1=46 },
new ChartData { X= "IND", YValue= 26, YValue1=16 },
new ChartData { X= "DEN", YValue= 26, YValue1=12 },
new ChartData { X= "MEX", YValue= 34, YValue1=32},
};
}
Shape
The Shape property allows you to customize the appearance of the markers by specifying different shapes.
@using Syncfusion.Blazor.Charts
<SfChart>
<ChartPrimaryXAxis ValueType="Syncfusion.Blazor.Charts.ValueType.Category"></ChartPrimaryXAxis>
<ChartSeriesCollection>
<ChartSeries DataSource="@ChartDataList" XName="X" YName="YValue" Type="Syncfusion.Blazor.Charts.ChartSeriesType.Scatter">
<ChartMarker Height="10" Width="10" Shape="ChartShape.Triangle" />
</ChartSeries>
<ChartSeries DataSource="@ChartDataList" XName="X" YName="YValue1" Type="Syncfusion.Blazor.Charts.ChartSeriesType.Scatter">
<ChartMarker Height="10" Width="10" Shape="ChartShape.Rectangle" />
</ChartSeries>
</ChartSeriesCollection>
</SfChart>
@code {
public class ChartData
{
public string X { get; set; }
public double YValue { get; set; }
public double YValue1 { get; set; }
}
public List<ChartData> ChartDataList = new List<ChartData>
{
new ChartData { X= "USA", YValue= 46, YValue1=56 },
new ChartData { X= "GBR", YValue= 27, YValue1=17 },
new ChartData { X= "CHN", YValue= 26, YValue1=36 },
new ChartData { X= "UK", YValue= 56, YValue1=16 },
new ChartData { X= "AUS", YValue= 12, YValue1=46 },
new ChartData { X= "IND", YValue= 26, YValue1=16 },
new ChartData { X= "DEN", YValue= 26, YValue1=12 },
new ChartData { X= "MEX", YValue= 34, YValue1=32},
};
}
Empty points
Data points with null
, double.NaN
or undefined
values are considered empty. Empty data points are ignored and not plotted on the chart.
Mode
Use the Mode
property to define how empty or missing data points are handled in the series. The default mode for empty points is Gap
.
@using Syncfusion.Blazor.Charts
<SfChart>
<ChartPrimaryXAxis ValueType="Syncfusion.Blazor.Charts.ValueType.Category"></ChartPrimaryXAxis>
<ChartSeriesCollection>
<ChartSeries DataSource="@ChartDataList" XName="X" YName="YValue" Type="Syncfusion.Blazor.Charts.ChartSeriesType.Scatter">
<ChartEmptyPointSettings Mode="EmptyPointMode.Gap"></ChartEmptyPointSettings>
<ChartMarker Visible="true" Height="10" Width="10"></ChartMarker>
</ChartSeries>
<ChartSeries DataSource="@ChartDataList" XName="X" YName="YValue1" Type="Syncfusion.Blazor.Charts.ChartSeriesType.Scatter">
<ChartEmptyPointSettings Mode="EmptyPointMode.Gap"></ChartEmptyPointSettings>
<ChartMarker Visible="true" Height="10" Width="10"></ChartMarker>
</ChartSeries>
</ChartSeriesCollection>
</SfChart>
@code {
public class ChartData
{
public string X { get; set; }
public double YValue { get; set; }
public double YValue1 { get; set; }
}
public List<ChartData> ChartDataList = new List<ChartData>
{
new ChartData { X= "USA", YValue= 46, YValue1=56 },
new ChartData { X= "GBR", YValue= 27, YValue1=17 },
new ChartData { X= "CHN", YValue= 26, YValue1=36 },
new ChartData { X= "UK", YValue= double.NaN, YValue1=double.NaN },
new ChartData { X= "AUS", YValue= 12, YValue1=46 },
new ChartData { X= "IND", YValue= 26, YValue1=16 },
new ChartData { X= "DEN", YValue= 26, YValue1=12 },
new ChartData { X= "MEX", YValue= 34, YValue1=32},
};
}
Fill
Use the Fill
property to customize the fill color of empty points in the series.
@using Syncfusion.Blazor.Charts
<SfChart>
<ChartPrimaryXAxis ValueType="Syncfusion.Blazor.Charts.ValueType.Category"></ChartPrimaryXAxis>
<ChartSeriesCollection>
<ChartSeries DataSource="@ChartDataList" XName="X" YName="YValue" Type="Syncfusion.Blazor.Charts.ChartSeriesType.Scatter">
<ChartEmptyPointSettings Fill="blue" Mode="EmptyPointMode.Average"></ChartEmptyPointSettings>
<ChartMarker Height="10" Width="10"></ChartMarker>
</ChartSeries>
<ChartSeries DataSource="@ChartDataList" XName="X" YName="YValue1" Type="Syncfusion.Blazor.Charts.ChartSeriesType.Scatter">
<ChartEmptyPointSettings Fill="green" Mode="EmptyPointMode.Average"></ChartEmptyPointSettings>
<ChartMarker Height="10" Width="10"></ChartMarker>
</ChartSeries>
</ChartSeriesCollection>
</SfChart>
@code {
public class ChartData
{
public string X { get; set; }
public double YValue { get; set; }
public double YValue1 { get; set; }
}
public List<ChartData> ChartDataList = new List<ChartData>
{
new ChartData { X= "USA", YValue= 46, YValue1=56 },
new ChartData { X= "GBR", YValue= 27, YValue1=17 },
new ChartData { X= "CHN", YValue= 26, YValue1=36 },
new ChartData { X= "UK", YValue= double.NaN, YValue1=double.NaN },
new ChartData { X= "AUS", YValue= 12, YValue1=46 },
new ChartData { X= "IND", YValue= 26, YValue1=16 },
new ChartData { X= "DEN", YValue= 26, YValue1=12 },
new ChartData { X= "MEX", YValue= 34, YValue1=32},
};
}
Border
Use the Border
property to customize the Width and Color of the border for empty points.
@using Syncfusion.Blazor.Charts
<SfChart>
<ChartPrimaryXAxis ValueType="Syncfusion.Blazor.Charts.ValueType.Category"></ChartPrimaryXAxis>
<ChartSeriesCollection>
<ChartSeries DataSource="@ChartDataList" XName="X" YName="YValue" Type="Syncfusion.Blazor.Charts.ChartSeriesType.Scatter">
<ChartEmptyPointSettings Fill="blue" Mode="EmptyPointMode.Average">
<ChartEmptyPointBorder Width="2" Color="#FF0000"></ChartEmptyPointBorder>
</ChartEmptyPointSettings>
<ChartMarker Height="10" Width="10"></ChartMarker>
</ChartSeries>
<ChartSeries DataSource="@ChartDataList" XName="X" YName="YValue1" Type="Syncfusion.Blazor.Charts.ChartSeriesType.Scatter">
<ChartEmptyPointSettings Fill="green" Mode="EmptyPointMode.Average">
<ChartEmptyPointBorder Width="2" Color="#FF0000"></ChartEmptyPointBorder>
</ChartEmptyPointSettings>
<ChartMarker Height="10" Width="10"></ChartMarker>
</ChartSeries>
</ChartSeriesCollection>
</SfChart>
@code {
public class ChartData
{
public string X { get; set; }
public double YValue { get; set; }
public double YValue1 { get; set; }
}
public List<ChartData> ChartDataList = new List<ChartData>
{
new ChartData { X= "USA", YValue= 46, YValue1=56 },
new ChartData { X= "GBR", YValue= 27, YValue1=17 },
new ChartData { X= "CHN", YValue= 26, YValue1=36 },
new ChartData { X= "UK", YValue= double.NaN, YValue1=double.NaN },
new ChartData { X= "AUS", YValue= 12, YValue1=46 },
new ChartData { X= "IND", YValue= 26, YValue1=16 },
new ChartData { X= "DEN", YValue= 26, YValue1=12 },
new ChartData { X= "MEX", YValue= 34, YValue1=32},
};
}
Events
Series render
The OnSeriesRender
event allows you to customize series properties, such as Data, Fill, and Series, before they are rendered on the chart.
@using Syncfusion.Blazor.Charts
<SfChart>
<ChartPrimaryXAxis ValueType="Syncfusion.Blazor.Charts.ValueType.Category"></ChartPrimaryXAxis>
<ChartEvents OnSeriesRender="SeriesRender"></ChartEvents>
<ChartSeriesCollection>
<ChartSeries DataSource="@ChartDataList" Name="Series1" XName="X" YName="YValue" Type="Syncfusion.Blazor.Charts.ChartSeriesType.Scatter" />
<ChartSeries DataSource="@ChartDataList" Name="Series2" XName="X" YName="YValue1" Type="Syncfusion.Blazor.Charts.ChartSeriesType.Scatter" />
</ChartSeriesCollection>
<ChartLegendSettings Visible="false"></ChartLegendSettings>
</SfChart>
@code {
public class ChartData
{
public string X { get; set; }
public double YValue { get; set; }
public double YValue1 { get; set; }
}
public void SeriesRender(SeriesRenderEventArgs args)
{
if (args.Series.Name == "Series1")
{
args.Fill = "red";
}
else if (args.Series.Name == "Series2")
{
args.Fill = "green";
}
}
public List<ChartData> ChartDataList = new List<ChartData>
{
new ChartData { X= "USA", YValue= 46, YValue1=56 },
new ChartData { X= "GBR", YValue= 27, YValue1=17 },
new ChartData { X= "CHN", YValue= 26, YValue1=36 },
new ChartData { X= "UK", YValue= 56, YValue1=16 },
new ChartData { X= "AUS", YValue= 12, YValue1=46 },
new ChartData { X= "IND", YValue= 26, YValue1=16 },
new ChartData { X= "DEN", YValue= 26, YValue1=12 },
new ChartData { X= "MEX", YValue= 34, YValue1=32},
};
}
Point render
The OnPointRender
event allows you to customize each data point before it is rendered on the chart.
@using Syncfusion.Blazor.Charts
<SfChart>
<ChartPrimaryXAxis ValueType="Syncfusion.Blazor.Charts.ValueType.Category"></ChartPrimaryXAxis>
<ChartEvents OnPointRender="PointRender"></ChartEvents>
<ChartSeriesCollection>
<ChartSeries DataSource="@ChartDataList" Name="Series1" XName="X" YName="YValue" Type="Syncfusion.Blazor.Charts.ChartSeriesType.Scatter">
<ChartMarker Height="10" Width="10" />
</ChartSeries>
<ChartSeries DataSource="@ChartDataList" Name="Series2" XName="X" YName="YValue1" Type="Syncfusion.Blazor.Charts.ChartSeriesType.Scatter">
<ChartMarker Height="10" Width="10" />
</ChartSeries>
</ChartSeriesCollection>
<ChartLegendSettings Visible="false"></ChartLegendSettings>
</SfChart>
@code {
public class ChartData
{
public string X { get; set; }
public double YValue { get; set; }
public double YValue1 { get; set; }
}
public void PointRender(PointRenderEventArgs args)
{
args.Fill = args.Point.X.ToString() == "UK" ? args.Series.YName == "YValue" ? "#E91E63" : "#FFC107" : args.Fill;
}
public List<ChartData> ChartDataList = new List<ChartData>
{
new ChartData { X= "USA", YValue= 46, YValue1=56 },
new ChartData { X= "GBR", YValue= 27, YValue1=17 },
new ChartData { X= "CHN", YValue= 26, YValue1=36 },
new ChartData { X= "UK", YValue= 56, YValue1=16 },
new ChartData { X= "AUS", YValue= 12, YValue1=46 },
new ChartData { X= "IND", YValue= 26, YValue1=16 },
new ChartData { X= "DEN", YValue= 26, YValue1=12 },
new ChartData { X= "MEX", YValue= 34, YValue1=32},
};
}
NOTE
Refer to our Blazor Charts feature tour page for its groundbreaking feature representations and also explore our Blazor Chart Example to know various chart types and how to represent time-dependent data, showing trends at equal intervals.