Constructor
new()
Create a stacked area plot with default settings.
Returns: StackedAreaPlot
Defaults:
- Fill opacity
0.7 - Stroke width
1.5 - Strokes enabled
- Absolute (non-normalized) stacking
- Legend at top-right
Building a Chart
with_x()
Set the x-axis values shared by all series.
Iterator of numeric x values. Accepts any type implementing
Into<f64>.Self
Call this before adding any series.
with_series()
Append a new series.
Iterator of y values for this series. Must have the same length as the x values set by
with_x.Self
Call with_color and with_legend immediately after to configure the series that was just added. These methods always operate on the most recently added series.
with_color()
Set the fill color of the most recently added series.
CSS color string
Self
When not called, the series falls back to the built-in default palette: steelblue, orange, green, red, purple, brown, pink, gray (cycling for more than eight series).
with_legend()
Set the legend label of the most recently added series.
Legend label text
Self
Series without a legend label are not shown in the legend box. Omit this call to exclude a series from the legend entirely.
Styling
with_fill_opacity()
Set the fill opacity applied to every band.
Fill opacity in
[0.0, 1.0] (default: 0.7)Self
Lower values let the background grid lines show through the bands; 1.0 gives solid fills.
with_stroke_width()
Set the stroke width for the top-edge line on each band.
Stroke width in pixels (default: 1.5)
Self
Has no effect when with_strokes(false) is set.
with_strokes()
Show or hide the stroke drawn along the top edge of each band.
Whether to show strokes (default: true)
Self
Setting false produces flat, borderless bands — useful when the color contrast between adjacent bands is sufficient to distinguish them without outlines.
Normalization
with_normalized()
Enable 100% percent-stacking.
Returns: Self
Each column is normalised so all series sum to 100% at every x value. The y-axis is rescaled to span 0–100%. Use this when you want to emphasise proportional composition rather than absolute magnitude.
Legend Position
with_legend_position()
Set the corner of the plot area where the legend box is placed.
Legend position. Options:
TopRight (default), TopLeft, BottomRight, BottomLeftSelf
Utility Methods
resolve_color()
Resolve the display color for series k, falling back to a built-in palette.
Series index
&str
Complete Example
Public Fields
X-axis values shared across all series
Y values for each series.
series[k][i] is the value for series k at x[i]Optional explicit fill color for each series (parallel to
series). None falls back to the built-in default color paletteOptional legend label for each series (parallel to
series). Series with None are omitted from the legend boxFill opacity applied to every band (default: 0.7)
Stroke width for the top-edge line on each band (default: 1.5)
Whether to draw a stroke along the top edge of each band (default: true)
When
true, each column is rescaled to sum to 100%; the y-axis spans 0–100%Corner of the plot area where the legend box is placed (default:
TopRight)