Skip to main content

DataSetCollection

Namespace: Wisej.Web.Ext.ChartJS4.Models

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

Observable collection for chart datasets that keeps chart back-references in sync.

public class DataSetCollection : ObservableCollection<ChartDataSet>

The data sets map to the Chart.js data.datasets array. Items added to the collection are bound to the owning Chart (and unbound when removed or replaced), and every change to the collection refreshes the chart. The collection can be assigned from a ChartDataSet[] or a List<ChartDataSet> through the implicit conversion operators.

Example:

chart.DataSets.Add(new BarDataSet { Label = "2024", Data = new object[] { 3, 5, 2 } });
chart.DataSets.Add(new BarDataSet { Label = "2025", Data = new object[] { 4, 6, 3 } });
chart.DataSets.RemoveAt(0);

Constructors​

Instance member DataSetCollection()​

Initializes a new empty dataset collection.

The collection is not bound to a chart until it is assigned to DataSets.

Example:

var dataSets = new DataSetCollection();
dataSets.Add(new LineDataSet { Label = "Sales" });
chart.DataSets = dataSets;

Instance member DataSetCollection(chart)​

Initializes a new empty dataset collection bound to a chart.

NameTypeDescription
chartChartJS4The owning ChartJS4 control, or null.

Example:

var dataSets = new DataSetCollection(chart);
chart.DataSets = dataSets;

Instance member DataSetCollection(items)​

Initializes a new dataset collection with initial items.

NameTypeDescription
itemsIEnumerable<ChartDataSet>The initial data sets, or null to create an empty collection.

Example:

var items = new List<ChartDataSet> { new LineDataSet { Label = "A" }, new LineDataSet { Label = "B" } };
chart.DataSets = new DataSetCollection(items);

Properties​

Instance member Chart​

ChartJS4: Returns or sets the owning chart.

Value: The ChartJS4 control that owns the data sets, or null.

Set automatically when the collection is assigned to DataSets. Changing the value rebinds the Chart reference of every data set in the collection.

Example:

var dataSets = new DataSetCollection(new[] { new PieDataSet() });
dataSets.Chart = chart; // dataSets[0].Chart == chart

Methods​

Protected member ClearItems()​

Protected member InsertItem(index, item)​

ParameterTypeDescription
indexInt32
itemChartDataSet

Protected member RemoveItem(index)​

ParameterTypeDescription
indexInt32

Protected member SetItem(index, item)​

ParameterTypeDescription
indexInt32
itemChartDataSet