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.
- C#
- VB.NET
public class DataSetCollection : ObservableCollection<ChartDataSet>
Public Class DataSetCollection
Inherits ObservableCollection(Of 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
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;
DataSetCollection(chart)
Initializes a new empty dataset collection bound to a chart.
Example:
var dataSets = new DataSetCollection(chart);
chart.DataSets = dataSets;
DataSetCollection(items)
Initializes a new dataset collection with initial items.
| Name | Type | Description |
|---|---|---|
| items | IEnumerable<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
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
ClearItems()
InsertItem(index, item)
| Parameter | Type | Description |
|---|---|---|
| index | Int32 | |
| item | ChartDataSet |
RemoveItem(index)
| Parameter | Type | Description |
|---|---|---|
| index | Int32 |
SetItem(index, item)
| Parameter | Type | Description |
|---|---|---|
| index | Int32 | |
| item | ChartDataSet |