stack() function transforms multiple datasets into a stacked format by adding a y0 property to each data point. This property defines the baseline for each stacked layer, allowing you to create stacked bar charts where series are visually stacked on top of each other.
Function signature
Parameters
An array of datasets to stack. Each dataset is an array of
Point objects with x and y properties.All datasets must have:- The same length
- Matching
xvalues at corresponding indices
Returns
An array of stacked datasets. Each point includes an additional
y0 property representing the baseline value for stacking.Point structure:How it works
The function processes data points at each x-coordinate position:- For the first series,
y0 = 0andyequals the cumulative value - For subsequent series,
y0equals the previous cumulative total - Each series is stacked on top of the previous one
Example
Important notes
- All input datasets must have the same length
- Corresponding data points across datasets must have matching
xvalues - The function assumes datasets are aligned by index position
- Works with both numeric and categorical (string) x-values
- The returned data points include a
y0property that bar series use for positioning