Skip to main content

Blazor Scatter Chart

A Blazor Bootstrap scatter chart components are based on basic line charts with the x-axis changed to a linear axis. To use a scatter chart, data must be passed as objects containing X and Y properties.

Blazor Chart Component - Blazor Scatter Chart

Parameters

NameTypeDefaultRequiredDescriptionAdded Version
Heightint?nullGets or sets chart container height.3.0.0
HeightUnitUnitUnit.PxGets or sets chart container height unit of measure.3.0.0
Widthint?nullGets or sets chart container width.3.0.0
WidthUnitUnitUnit.PxGets or sets chart container width unit of measure.3.0.0

Methods

NameReturn typeDescriptionAdded Version
AddDataAsync(ChartData chartData, string dataLabel, IChartDatasetData data)Task<ChartData>Adds data to chart.3.0.0
AddDataAsync(ChartData chartData, string dataLabel, List<IChartDatasetData> data)Task<ChartData>Adds dataset to chart.3.0.0
AddDatasetAsync(ChartData chartData, IChartDataset chartDataset, IChartOptions chartOptions)Task<ChartData>Adds dataset to chart.3.0.0
InitializeAsync(ChartData chartData, IChartOptions chartOptions, string[]? plugins = null)TaskInitialize the chat.3.0.0
ResizeAsync(int width, int height, Unit widthUnit = Unit.Px, Unit heightUnit = Unit.Px)TaskResize the chart.3.0.0
UpdateAsync(ChartData chartData, IChartOptions chartOptions)TaskUpdate the chart.3.0.0

ChartData Members

Property NameTypeDefaultRequiredDescriptionAdded Version
DatasetsList<IChartDataset>null✔️Gets or sets the Datasets.3.0.0
LabelsList<string>null✔️Gets or sets the Labels.3.0.0

PieChartDataset Members

info

RadarChartDataset implements IChartDataset and inherits from the parent class ChartDataset.

Property NameTypeDefaultRequiredDescriptionAdded Version
BackgroundColorstringrgba(0, 0, 0, 0.1)Get or sets the line fill color.3.0.0
BorderCapStylestringbuttCap style of the line. Supported values are 'butt', 'round', and 'square'.3.0.0
BorderColorstringrgba(0, 0, 0, 0.1)Get or sets the line color.3.0.0
BorderDashList<double>?nullGets or sets the length and spacing of dashes.3.0.0
BorderDashOffsetdouble0.0Offset for line dashes.3.0.0
BorderJoinStylestringmiterLine joint style. There are three possible values for this property: 'round', 'bevel', and 'miter'.3.0.0
BorderWidthdouble3Gets or sets the line width (in pixels).3.0.0
Clipstring?nullHow to clip relative to chartArea. Positive value allows overflow, negative value clips that many pixels inside chartArea. 0 = clip at chartArea. Clipping can also be configured per side: clip: {left: 5, top: false, right: -2, bottom: 0}1.0.0
CubicInterpolationModestringdefaultSupported values are 'default', and 'monotone'.3.0.0
DataList<ScatterChartDataPoint?>?null✔️Get or sets the Data.3.0.0
DatalabelsPieChartDatasetDataLabelsGet or sets the data labels3.0.0
DrawActiveElementsOnTopList<bool>?nullDraw the active points of a dataset over the other points of the dataset.3.0.0
FillboolfalseHow to fill the area under the line.3.0.0
HiddenboolfalseConfigures the visibility state of the dataset. Set it to true, to hide the dataset from the chart.3.0.0
HoverBackgroundColorstring?nullThe line fill color when hovered.3.0.0
HoverBorderCapStylestring?nullCap style of the line when hovered.3.0.0
HoverBorderColorstring?nullThe line color when hovered.3.0.0
HoverBorderDashList<double>?nullGets or sets the length and spacing of dashes when hovered.3.0.0
HoverBorderDashOffsetdouble?nullOffset for line dashes when hovered.3.0.0
HoverBorderJoinStylestringmiterLine joint style. There are three possible values for this property: 'round', 'bevel', and 'miter'.3.0.0
HoverBorderWidthdouble?nullThe bar border width when hovered (in pixels) when hovered.3.0.0
IndexAxisstring?nullThe base axis of the dataset. 'x' for horizontal lines and 'y' for vertical lines.3.0.0
Labelstring?nullThe label for the dataset which appears in the legend and tooltips.3.0.0
Orderint0The drawing order of dataset. Also affects order for stacking, tooltip and legend.3.0.0
PointBackgroundColorList<string>?nullThe fill color for points.3.0.0
PointBorderColorList<string>?nullThe border color for points.3.0.0
PointBorderWidthList<double>?nullThe width of the point border in pixels.3.0.0
PointHitRadiusList<double>?nullThe pixel size of the non-displayed point that reacts to mouse events.3.0.0
PointHoverBackgroundColorList<string>?nullPoint background color when hovered.3.0.0
PointHoverBorderColorList<string>?nullPoint border color when hovered.3.0.0
PointHoverBorderWidthList<double>?nullBorder width of point when hovered.3.0.0
PointHoverRadiusList<double>?nullThe radius of the point when hovered.3.0.0
PointRadiusList<double>?nullThe radius of the point shape. If set to 0, the point is not rendered.3.0.0
PointRotationList<double>?nullThe rotation of the point in degrees.3.0.0
PointStyleList<string>?nullStyle of the point. Supported values are 'circle', 'cross', 'crossRot', 'dash', 'line', 'rect', 'rectRounded', 'rectRot', 'star', and 'triangle' to style.3.0.0
ShowLineboolfalseIf false, the lines between points are not drawn. By default, the scatter chart will override the showLine property of the line chart to false.3.0.0
SpanGapsbool?nullIf true, lines will be drawn between points with no or null data. If false, points with null data will create a break in the line. Can also be a number specifying the maximum gap length to span. The unit of the value depends on the scale used.3.0.0
Steppedboolfalsetrue to show the line as a stepped line (tension will be ignored).3.0.0
Tensiondouble0Bezier curve tension of the line. Set to 0 to draw straight lines. This option is ignored if monotone cubic interpolation is used.3.0.0
XAxisIDstring?nullThe ID of the x axis to plot this dataset on.3.0.0
YAxisIDstring?nullThe ID of the y axis to plot this dataset on.3.0.0

ScatterChartDataPoint Members

Property NameTypeDefaultRequiredDescriptionAdded Version
Xdouble0Gets or sets the x axis value.3.0.0
Ydouble0Gets or sets the y axis value.3.0.0

ScatterChartDatasetDataLabels Members

info

ScatterChartDatasetDataLabels inherits from the parent class ChartDatasetDataLabels.

Property NameTypeDefaultRequiredDescriptionAdded Version
AlignmentAlignmentAlignment.NoneGets or sets the data labels alignment.3.0.0
AnchorAnchorAnchor.NoneGets or sets the data labels anchor.3.0.0
BorderWidthdouble2Gets or sets the border width3.0.0

ScatterChartOptions Members

info

ScatterChartOptions inherits from the parent class ChartOptions.

Property NameTypeDefaultRequiredDescriptionAdded Version
IndexAxisstring?nullThe base axis of the chart. 'x' for vertical charts and 'y' for horizontal charts.3.0.0
InteractionInteractionGets or sets the Interaction.3.0.0
LayoutChartLayoutGets or sets the ChartLayout.3.0.0
Localestring?Gets or sets the locale. By default, the chart is using the default locale of the platform which is running on.3.0.0
MaintainAspectRatiobooltrueMaintain the original canvas aspect ratio (width / height) when resizing.3.0.0
PluginsScatterChartPluginsGets or sets the Plugins.3.0.0
ResponsiveboolfalseGets or sets the Responsive.3.0.0
ScalesScalesGets or sets the Scales.3.0.0

Examples

Prerequisites

Refer to the getting started guide for setting up charts.

How it works

In the following example, a categorical 12-color palette is used.

tip

For data visualization, you can use the predefined palettes ColorBuilder.CategoricalTwelveColors for a 12-color palette and ColorBuilder.CategoricalSixColors for a 6-color palette. These palettes offer a range of distinct and visually appealing colors that can be applied to represent different categories or data elements in your visualizations.

Blazor Bootstrap: Pie Chart Component - How it works
<ScatterChart @ref="scatterChart" Width="560" Height="480" />
@code {
private ScatterChart scatterChart = default!;
private ScatterChartOptions scatterChartOptions = default!;
private ChartData chartData = default!;

private Random random = new();

protected override void OnInitialized()
{
chartData = new ChartData
{
Datasets = new()
{
GetRandomRadarChartDataset(0),
GetRandomRadarChartDataset(1),
GetRandomRadarChartDataset(2)
}
};

scatterChartOptions = new() { };
}

protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender)
{
await scatterChart.InitializeAsync(chartData, scatterChartOptions);
}
await base.OnAfterRenderAsync(firstRender);
}

#region Data Preparation

private ScatterChartDataset GetRandomRadarChartDataset(int recordIndex)
{
var c = ColorUtility.CategoricalTwelveColors[recordIndex].ToColor();

return new ScatterChartDataset
{
Label = $"Team {recordIndex + 1}",
Data = GetRandomData(),
BackgroundColor = c.ToRgbaString(), // RGBA
BorderColor = c.ToRgbString(), // RGB
BorderWidth = 2,
HoverBorderWidth = 4,
};
}

private List<ScatterChartDataPoint?> GetRandomData()
{
var data = new List<ScatterChartDataPoint?>();
for (var index = 0; index < 10; index++)
{
data.Add(new(random.Next(200), random.Next(200)));
}

return data;
}

#endregion Data Preparation
}

See the demo here.