Skip to main content

ChartDataSet

Namespace: Wisej.Web.Ext.ChartJS4.Models

Assembly: Wisej.Web.Ext.ChartJS4 (4.1.0.0)

Base class for all chart data sets. Represents data to be plotted on a chart with flexible serialization.

public class ChartDataSet : ChartModelBase

Each instance is serialized to one entry of the Chart.js data.datasets array. Use the specialized subclasses (LineDataSet, BarDataSet, PieDataSet, BubbleDataSet, ScatterDataSet, RadarDataSet, PolarAreaDataSet) to access type-specific options. Changing any property refreshes the owning chart. Chart.js options not exposed as properties can be added through ExtensionData.

Example:

var chart = new ChartJS4();
chart.Labels = new[] { "Jan", "Feb", "Mar" };
chart.DataSets.Add(new ChartDataSet
{
Label = "Sales",
Data = new object[] { 10, 20, 15 },
BackgroundColor = Color.SteelBlue
});

Constructors​

Instance member ChartDataSet()​

Initializes a new instance of the ChartDataSet class.

The new dataset has the label "Dataset" and no Type, so it is plotted using the chart's main type.

Example:

var dataSet = new ChartDataSet();
dataSet.Label = "Visitors";
dataSet.Data = new object[] { 120, 98, 143 };
chart.DataSets.Add(dataSet);

Properties​

Instance member BackgroundColor​

Object: Returns or sets the fill color or pattern.

Value: A Color, a CSS color string (e.g. "rgba(75, 192, 192, 0.2)"), or an array of colors (one per data point). The default is null (Chart.js default). Maps to the Chart.js backgroundColor option.

Example:

var bars = new BarDataSet { Label = "Sales" };
bars.BackgroundColor = Color.FromArgb(128, Color.SteelBlue);

var pie = new PieDataSet { Label = "Share" };
pie.BackgroundColor = new object[] { Color.Red, "#36a2eb", "rgb(255, 205, 86)" };

Instance member BorderColor​

Object: Returns or sets the border color.

Value: A Color, a CSS color string, or an array of colors (one per data point). The default is null (Chart.js default). Maps to the Chart.js borderColor option.

For line charts this is the color of the line itself.

Example:

var line = new LineDataSet { Label = "Sales" };
line.BorderColor = Color.SteelBlue;
line.BorderWidth = 2;

Instance member BorderWidth​

Int32: Returns or sets the border width in pixels. (Default: 0)

Value: An Int32. The default is 0, which is not serialized so the Chart.js default applies. Maps to the Chart.js borderWidth option.

Example:

var bars = new BarDataSet { Label = "Sales" };
bars.BorderColor = Color.Navy;
bars.BorderWidth = 1;

Instance member Data​

Object[]: Returns or sets the data to plot.

Value: An array of values. The default is null. Maps to the Chart.js data option.

Items can be numbers (matched to the chart Labels by index), null to create gaps, or objects such as new { x = 1, y = 2 } for scatter charts and new { x = 1, y = 2, r = 5 } for bubble charts.

Example:

var line = new LineDataSet { Label = "Sales" };
line.Data = new object[] { 12, 19, 3, 5, 2 };

var scatter = new ScatterDataSet { Label = "Points" };
scatter.Data = new object[] { new { x = 1, y = 4 }, new { x = 3, y = 7 } };

Instance member Hidden​

Boolean: Returns or sets a value indicating whether the dataset is hidden. (Default: False)

Value: true to hide the dataset; otherwise false. The default is false. Maps to the Chart.js hidden option.

A hidden dataset is not rendered but still appears (struck through) in the legend.

Example:

var dataSet = chart.DataSets[0];
dataSet.Hidden = true;

Instance member Label​

String: Returns or sets the label for the dataset which appears in the legend and tooltips.

Value: A String. The default is "Dataset". Maps to the Chart.js label option.

Example:

var dataSet = new BarDataSet { Label = "Revenue 2024" };
chart.DataSets.Add(dataSet);

Instance member Order​

Nullable<Int32>: Returns or sets the drawing order of the dataset. Also affects order for stacking, tooltip and legend.

Value: A nullable Int32. The default is null (Chart.js default 0). Maps to the Chart.js order option.

Datasets with a lower order are drawn on top of datasets with a higher order.

Example:

var line = new LineDataSet { Label = "Trend", Order = 0 };
var bars = new BarDataSet { Label = "Sales", Order = 1 };
chart.DataSets.Add(line);
chart.DataSets.Add(bars);

Instance member Stack​

String: Returns or sets the ID of the group to which the dataset belongs (when stacking datasets).

Value: A String identifying the stack group. The default is null. Maps to the Chart.js stack option.

Datasets with the same stack ID are stacked together when the axis Stacked option is enabled.

Example:

chart.DataSets.Add(new BarDataSet { Label = "2023", Data = new object[] { 5, 7 }, Stack = "A" });
chart.DataSets.Add(new BarDataSet { Label = "2024", Data = new object[] { 6, 9 }, Stack = "A" });
chart.ChartOptions.Scales.X.Stacked = true;
chart.ChartOptions.Scales.Y.Stacked = true;

Instance member Type​

String: Returns or sets the type of chart that plots this data set (overrides the main chart type).

Value: A Chart.js chart type string such as "line", "bar", "bubble", "scatter", "radar", "pie", "doughnut" or "polarArea". The default is null (use the chart's type). Maps to the Chart.js type dataset option.

Setting this property allows mixed charts, e.g. a line dataset drawn on top of a bar chart. The specialized dataset classes set this value in their constructors.

Example:

chart.ChartType = ChartType.Bar;
chart.DataSets.Add(new ChartDataSet { Label = "Sales", Data = new object[] { 5, 8, 6 } });
chart.DataSets.Add(new ChartDataSet { Label = "Target", Data = new object[] { 6, 6, 6 }, Type = "line" });

Instance member YAxisID​

String: Returns or sets the ID of the y-axis to plot this dataset on.

Value: A String matching a key in the chart's scales configuration (e.g. "y"). The default is null (the first y-axis). Maps to the Chart.js yAxisID option.

Additional axes (e.g. "y1") can be defined through ExtensionData.

Example:

var dataSet = new LineDataSet { Label = "Temperature", YAxisID = "y" };
chart.DataSets.Add(dataSet);

Methods​

Instance member ResetBorderWidth()​

Resets the BorderWidth property to its default value of 0.

Used by the Visual Studio designer when the user resets the property.

Example:

dataSet.ResetBorderWidth();

Instance member ResetHidden()​

Resets the Hidden property to its default value of false.

Used by the Visual Studio designer when the user resets the property.

Example:

dataSet.ResetHidden();

Instance member ShouldSerializeBorderWidth()​

Determines whether the BorderWidth property should be serialized by the designer.

Returns: Boolean. true if BorderWidth is not 0 (its default value); otherwise false.

Used by the Visual Studio designer to decide whether to generate code for the property.

Example:

if (dataSet.ShouldSerializeBorderWidth())
dataSet.ResetBorderWidth();

Instance member ShouldSerializeHidden()​

Determines whether the Hidden property should be serialized by the designer.

Returns: Boolean. true if Hidden is not false (its default value); otherwise false.

Used by the Visual Studio designer to decide whether to generate code for the property.

Example:

if (dataSet.ShouldSerializeHidden())
dataSet.ResetHidden();

Inherited By​

NameDescription
LineDataSetData set for line charts.
BarDataSetData set for bar charts.
PieDataSetData set for pie and doughnut charts.
BubbleDataSetData set for bubble charts.
ScatterDataSetData set for scatter charts.
RadarDataSetData set for radar charts.
PolarAreaDataSetData set for polar area charts.