hydroxy

Stacked area chart

Parts of a total over time, stacked from zero, scaled to 100%, or as a streamgraph. Hover to read every series at one point.

Visits by source

Weekly visits, stacked from zero. The dashed line is the quarter's weekly goal.

Weekly visits by traffic source
Organic searchPaid searchReferralSocialEmailTotal
Jan 642k18k9k6k4k79k
Jan 1344k20k9k8k12k93k
Jan 2047k22k10k7k5k91k
Jan 2745k25k12k9k4k95k
Feb 349k24k11k14k13k111k
Feb 1052k21k10k18k5k106k
Feb 1755k19k13k12k4k103k
Feb 2453k23k14k10k14k114k
Mar 357k26k13k9k5k110k
Mar 1060k28k15k11k4k118k
Mar 1762k27k16k10k15k130k
Mar 2465k30k15k12k6k128k

Share of visits

The same data scaled to 100%, so each source's share reads directly.

Share of weekly visits by source
Organic searchPaid searchReferralSocialEmailTotal
Jan 642k18k9k6k4k79k
Jan 1344k20k9k8k12k93k
Jan 2047k22k10k7k5k91k
Jan 2745k25k12k9k4k95k
Feb 349k24k11k14k13k111k
Feb 1052k21k10k18k5k106k
Feb 1755k19k13k12k4k103k
Feb 2453k23k14k10k14k114k
Mar 357k26k13k9k5k110k
Mar 1060k28k15k11k4k118k
Mar 1762k27k16k10k15k130k
Mar 2465k30k15k12k6k128k

Traffic streamgraph

A wiggle baseline keeps each ribbon as flat as it can. Values are relative, so there is no axis.

Weekly visits by source, as a streamgraph
Organic searchPaid searchReferralSocialEmailTotal
Jan 642k18k9k6k4k79k
Jan 1344k20k9k8k12k93k
Jan 2047k22k10k7k5k91k
Jan 2745k25k12k9k4k95k
Feb 349k24k11k14k13k111k
Feb 1052k21k10k18k5k106k
Feb 1755k19k13k12k4k103k
Feb 2453k23k14k10k14k114k
Mar 357k26k13k9k5k110k
Mar 1060k28k15k11k4k118k
Mar 1762k27k16k10k15k130k
Mar 2465k30k15k12k6k128k

Usage

use hydroxy_leptos::chart_frame::ChartFrame;
use hydroxy_leptos::stacked_area_chart::*;
use leptos::prelude::*;

#[component]
pub fn Demo() -> impl IntoView {
    // Stored signals are Copy, so the three charts can share them.
    let weeks = Signal::stored(
        [
            "Jan 6", "Jan 13", "Jan 20", "Jan 27", "Feb 3", "Feb 10", "Feb 17", "Feb 24", "Mar 3", "Mar 10", "Mar 17",
            "Mar 24",
        ]
        .map(String::from)
        .to_vec(),
    );
    // Weekly visits in thousands, bottom of the stack first.
    let traffic = Signal::stored(vec![
        Series::new("Organic search", [42.0, 44.0, 47.0, 45.0, 49.0, 52.0, 55.0, 53.0, 57.0, 60.0, 62.0, 65.0]),
        Series::new("Paid search", [18.0, 20.0, 22.0, 25.0, 24.0, 21.0, 19.0, 23.0, 26.0, 28.0, 27.0, 30.0]),
        Series::new("Referral", [9.0, 9.0, 10.0, 12.0, 11.0, 10.0, 13.0, 14.0, 13.0, 15.0, 16.0, 15.0]),
        Series::new("Social", [6.0, 8.0, 7.0, 9.0, 14.0, 18.0, 12.0, 10.0, 9.0, 11.0, 10.0, 12.0]),
        Series::new("Email", [4.0, 12.0, 5.0, 4.0, 13.0, 5.0, 4.0, 14.0, 5.0, 4.0, 15.0, 6.0]),
    ]);
    let thousands = |v: f64| format!("{v:.0}k");

    view! {
        <div style="display: grid; gap: var(--space-10);">
            <ChartFrame title="Visits by source" description="Weekly visits, stacked from zero. The dashed line is the quarter's weekly goal.">
                <StackedAreaChart
                    series=traffic
                    labels=weeks
                    label="Weekly visits by traffic source"
                    curve=Curve::Monotone
                    format=thousands
                    annotations=vec![Annotation::y_line(120.0, "Goal")]
                />
            </ChartFrame>
            <ChartFrame title="Share of visits" description="The same data scaled to 100%, so each source's share reads directly.">
                <StackedAreaChart series=traffic labels=weeks label="Share of weekly visits by source" offset=StackOffset::Expand format=thousands />
            </ChartFrame>
            <ChartFrame title="Traffic streamgraph" description="A wiggle baseline keeps each ribbon as flat as it can. Values are relative, so there is no axis.">
                <StackedAreaChart series=traffic labels=weeks label="Weekly visits by source, as a streamgraph" offset=StackOffset::Wiggle curve=Curve::Monotone format=thousands />
            </ChartFrame>
        </div>
    }
}

Anatomy

Componentdata-partRenders
StackedAreaChartrootfigure with data-variant set to the offset, and a screen-reader table of every value
areaOne ribbon per series; the hovered one stays strong while the rest fade
crosshairVertical line at the active x
dotThe top of each ribbon at the active x
tooltipEvery series at that x, top of the stack first, and the total
legendShown for two or more series
annotationReference lines, bands and points

Keyboard

KeyDoes
ArrowLeft / ArrowRightPrevious or next x
Home / EndFirst or last x
EscapeHide the tooltip

Props

PropTypeNotes
seriesVec<Series>Required. Bottom of the stack first; past six, the smallest fold into Other
labelsVec<String>Required. One per x position
labelStringRequired. What the chart shows; the accessible name
offsetStackOffsetZero (default), Expand, Wiggle or Silhouette
curveCurveLinear (default) or Monotone
heightu16Plot height in px. Default 240
formatFn(f64) -> StringFormats the ticks, tooltip and table
annotationsVec<Annotation>x is a point index; with Expand, y is a share 0..=1

Events

PropTypeNotes
on_hoverCallback<Option<Datum>>The mark under the pointer or keyboard focus changes, or is left. Fires only on a change
on_selectCallback<Datum>Click, tap or Enter on a mark
Actions
Button
Icon button
Toolbar
Theme menu
Display
Avatar
Badge
Card
Chip
Code block
Markdown
Doc card
Due pill
Kbd
Priority mark
Source chip
Space icon
Status diamond
Tag
Value diff
Carousel
Reveal
Media timeline
QR code
Transcript viewer
Audio waveform
Audio player
Forms
Calendar
Checkbox
Combobox
Date picker
Color picker
Cron builder
Theme editor
Mention input
Signature pad
Image cropper
Date field
Date range picker
Duration field
Quantity stepper
Filter chip
Input
Markdown editor
Radio group
Search field
Segmented control
Select
Slider
Range slider
Rating
Toggle button
File dropzone
Upload queue
Attachment
Switch
Tags input
Number field
Money field
Phone field
Time field
OTP input
Password field
Questionnaire
Availability picker
Voice input
Recording control
Inline edit
Async validated input
Shortcut recorder
Data
Spreadsheet grid
Week scheduler
Virtual list
Stat card
Step track
Kanban board
Sortable list
Filter builder
Data table
Grid
Access editor
File manager
Gantt chart
Log stream
Diff viewer
JSON inspector
Terminal
Node editor
Whiteboard
Navigation
Table of contents
Breadcrumb
Tabs
Wizard
Nav item
Nav section
Tree view
Pagination
Menubar
Navigation menu
Saved views
Layout
Master detail
App shell
Sidebar layout
Resizable panels
Dashboard layout
Dock layout
Feedback
Callout
Check list
Empty state
Progress bar
Toast
Approval card
Skeleton
Notification center
Bars
Bar chart
Diverging bar chart
Span chart
Pictogram chart
Stacked bar chart
Funnel chart
Bullet chart
Waffle chart
Marimekko chart
Dot plot chart
Error bar chart
Pareto chart
Waterfall chart
Lollipop chart
Grouped bar chart
Bar race chart
KPIs and frames
Chart frame
Metric card
Sparkline
Points
Scatter chart
Smith chart
Strip plot
Beeswarm chart
Parallel coordinates
Ternary chart
Bland-Altman chart
Quiver chart
Connected scatter chart
Grids and tables
Heatmap chart
Chart table
Cohort chart
Radial
Radial charts
Radar chart
Polar area chart
Stat ring
Clock chart
Spiral chart
Lines and areas
Bump chart
Slope chart
Line chart
Composed chart
Small multiples
Cycle plot chart
Horizon chart
Stacked area chart
Threshold chart
Split line chart
Linked charts
Confidence band chart
Forecast fan chart
Step chart
Range area chart
Distributions
Contour chart
Histogram
Box plot
Density chart
Ridgeline chart
Violin chart
Q-Q chart
Survival chart
ECDF chart
Raincloud plot
Forest plot
Maps
Geo map
Bubble map
Hexbin map
Cartogram
Flow map
Parts of a whole
Donut chart
Voronoi treemap
Nested donut chart
Treemap chart
Sunburst chart
Bubble pack chart
Icicle chart
Flame graph chart
Pie chart
Word cloud
Relationships
Sankey chart
Network chart
Chord chart
UpSet chart
Venn chart
Alluvial chart
Adjacency matrix chart
Dependency graph chart
Tree chart
Arc diagram
Hive plot
Edge bundling
Finance
Candlestick chart
OHLC chart
Depth chart
Renko chart
Time
Timeline chart
Calendar heatmap chart
Spectrogram chart
Marey chart
Overlays
Tour
Lightbox
Alert dialog
Command palette
Dialog
Menu
Popover
Tooltip
Sheet
Hover card
Context menu
Utilities
Pacer
Hotkeys
Disclosure
Accordion
Collapsible
Chat
Chat bubble
Voice session
Composer
Thread
Thread list
Assistant composer
Assistant MCP
Assistant modal
Assistant thread
Assistant thread list
Message scroller
Insight note
Emoji picker
Tool trace
Model picker
Citation popover
Activity
Activity feed
Comment thread
Timeline
Presence bar
Live cursors
Reaction bar
Guides
Getting started
All components
All charts