hydroxy

Bar chart

Compare one measure across categories or weeks. Bars are grey with one picked out, so the eye goes to the value that matters.

Interviews read

Per week, since the start of September, against a goal of 15.

Interviews read per week
Interviews read per week
2 Sep6
9 Sep9
16 Sep7
23 Sep12
30 Sep10
7 Oct14
14 Oct11
21 Oct17

Monthly spend

By team, switch the month to watch the bars glide.

Monthly spend by team
Monthly spend by team
Research£4.2k
Support£2.6k
Sales£3.1k
Product£1.8k

Interviews by source

Horizontal bars keep long names readable.

Interviews by source
Interviews by source
Customer interviews18
Support tickets14
Sales call notes11
In-app survey comments8
App store reviews5

Usage

use hydroxy_leptos::bar_chart::*;
use hydroxy_leptos::chart_frame::ChartFrame;
use hydroxy_leptos::segmented::{Segmented, SegmentedItem, SegmentedOption};
use leptos::prelude::*;

#[component]
pub fn Demo() -> impl IntoView {
    let weeks = vec![
        Datum::new("2 Sep", 6.0),
        Datum::new("9 Sep", 9.0),
        Datum::new("16 Sep", 7.0),
        Datum::new("23 Sep", 12.0),
        Datum::new("30 Sep", 10.0),
        Datum::new("7 Oct", 14.0),
        Datum::new("14 Oct", 11.0),
        Datum::new("21 Oct", 17.0),
    ];
    let october = vec![
        Datum::new("Research", 4200.0),
        Datum::new("Support", 2600.0),
        Datum::new("Sales", 3100.0),
        Datum::new("Product", 1800.0),
    ];
    let september = vec![
        Datum::new("Research", 3400.0),
        Datum::new("Support", 2900.0),
        Datum::new("Sales", 2200.0),
        Datum::new("Product", 2500.0),
    ];
    let sources = vec![
        Datum::new("Customer interviews", 18.0),
        Datum::new("Support tickets", 14.0),
        Datum::new("Sales call notes", 11.0),
        Datum::new("In-app survey comments", 8.0),
        Datum::new("App store reviews", 5.0),
    ];
    let (month, set_month) = signal(Some(String::from("oct")));
    // Same categories, new values: each bar glides to its new height.
    let spend =
        Signal::derive(move || if month.get().as_deref() == Some("sep") { september.clone() } else { october.clone() });

    view! {
        <div style="display: grid; gap: var(--space-10);">
            // The latest week is picked out; hover any bar, or focus the plot and use the
            // arrow keys, to read it. The goal line widens the axis to fit.
            <ChartFrame title="Interviews read" description="Per week, since the start of September, against a goal of 15.">
                <BarChart data=weeks label="Interviews read per week" annotations=vec![Annotation::y_line(15.0, "Goal")] />
            </ChartFrame>

            // A chosen bar, every value shown, money formatting, and live data.
            <Segmented
                label="Month"
                items=vec![SegmentedOption::new("sep"), SegmentedOption::new("oct")]
                value=month
                on_value_change=move |v| set_month.set(Some(v))
            >
                <SegmentedItem value="sep" label="September" />
                <SegmentedItem value="oct" label="October" />
            </Segmented>
            <ChartFrame title="Monthly spend" description="By team, switch the month to watch the bars glide.">
                <BarChart
                    data=spend
                    label="Monthly spend by team"
                    height=160
                    highlight=Highlight::Index(0)
                    show_values=true
                    format=|v: f64| {
                        let k = v / 1000.0;
                        if k.fract() == 0.0 { format!("£{k:.0}k") } else { format!("£{k:.1}k") }
                    }
                />
            </ChartFrame>

            // Horizontal suits long category names.
            <ChartFrame title="Interviews by source" description="Horizontal bars keep long names readable.">
                <BarChart
                    data=sources
                    label="Interviews by source"
                    orientation=Orientation::Horizontal
                    height=200
                    highlight=Highlight::Index(0)
                    show_values=true
                    annotations=vec![Annotation::y_line(11.2, "Average")]
                />
            </ChartFrame>
        </div>
    }
}

Anatomy

Componentdata-partRenders
BarChartrootfigure with a screen-reader table of every value
gridlineRecessive gridlines at nice round ticks, starting at zero
columnOne per value; hovering reveals its value
bar4px rounded top, --chart-muted, or --chart-1 when highlighted
labelCategory name, truncated with an ellipsis
barsFocusable plot; arrow keys move between bars
tooltipCategory and value of the active bar
annotationReference line, band or labelled point; turned round for horizontal bars

Keyboard

KeyDoes
ArrowLeft / ArrowRightMove to the previous or next bar
Home / EndJump to the first or last bar
EscapeHide the tooltip

Props

PropTypeNotes
dataVec<Datum>Required. Datum::new(label, value), in display order
labelStringRequired. What the chart shows; the accessible name
orientationOrientationVertical (default) or Horizontal, with labels down the left
heightu16Plot height in px. Default 180
highlightHighlightLast (default), Index(i) or Off
show_valuesboolShow every value, not just the highlighted and hovered ones
formatFn(f64) -> StringFormats ticks, values and the table
annotationsVec<Annotation>Reference lines, bands and labelled points; x is a category index, y a value

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