Charts
dot-plot
Values as dots along a shared axis, one row per category: plain dots for one or more series, a lollipop (a stick to the dot), a dumbbell (two values joined, for a before and after), or a beeswarm (every single value as its own dot, packed so none overlap).
When to use it
Comparing values across categories with less ink than bars, especially when zero is not meaningful (dot, dumbbell), showing a change between two moments per category (dumbbell), or showing every observation in a few groups (beeswarm). For totals from zero use bar-chart; for a summary of spread use box-plot.
See it working
The demonstration the browser checks drive, with the keyboard as well as the pointer. More of it is on the Charts page.
Scatter and bubble
- Tea
- Coffee
- Cocoa
| name | Price | Rating | Sold | kind |
|---|---|---|---|---|
| Blend 1 | 6.2 | 3.1 | 626 | Tea |
| Blend 32 | 6.4 | 4.9 | 540 | Coffee |
| Blend 15 | 7.6 | 4.5 | 261 | Cocoa |
| Blend 23 | 8.1 | 4.1 | 429 | Coffee |
| Blend 9 | 8.8 | 3.6 | 369 | Cocoa |
| Blend 35 | 11 | 5 | 430 | Coffee |
| Blend 7 | 11.3 | 5 | 189 | Tea |
| Blend 31 | 11.6 | 3.5 | 46 | Tea |
| Blend 18 | 12.4 | 3.3 | 120 | Cocoa |
| Blend 14 | 12.4 | 3.9 | 52 | Coffee |
| Blend 6 | 12.6 | 3.6 | 361 | Cocoa |
| Blend 16 | 13.7 | 3.9 | 608 | Tea |
| Blend 3 | 14.4 | 3.5 | 372 | Cocoa |
| Blend 27 | 15.3 | 3.7 | 475 | Cocoa |
| Blend 28 | 15.9 | 4.5 | 626 | Tea |
| Blend 26 | 15.9 | 4.6 | 43 | Coffee |
| Blend 11 | 16 | 4.2 | 448 | Coffee |
| Blend 29 | 16 | 4.6 | 298 | Coffee |
| Blend 34 | 16.7 | 4.4 | 637 | Tea |
| Blend 25 | 16.7 | 4.9 | 621 | Tea |
| Blend 33 | 17.4 | 3 | 411 | Cocoa |
| Blend 20 | 17.4 | 3.7 | 66 | Coffee |
| Blend 30 | 17.6 | 4.5 | 371 | Cocoa |
| Blend 21 | 18.3 | 4.8 | 369 | Cocoa |
| Blend 2 | 18.6 | 4 | 283 | Coffee |
| Blend 17 | 18.7 | 4.4 | 238 | Coffee |
| Blend 4 | 19.1 | 3.5 | 134 | Tea |
| Blend 10 | 19.7 | 3.1 | 588 | Tea |
| Blend 5 | 19.8 | 4 | 158 | Coffee |
| Blend 36 | 20.5 | 4.2 | 538 | Cocoa |
| Blend 13 | 20.9 | 3.1 | 145 | Tea |
| Blend 22 | 20.9 | 4.3 | 592 | Tea |
| Blend 8 | 21.8 | 3.4 | 126 | Coffee |
| Blend 24 | 22 | 4.9 | 543 | Cocoa |
| Blend 19 | 22.4 | 3.6 | 154 | Tea |
| Blend 12 | 23.4 | 4.2 | 593 | Cocoa |
Histogram
| Minutes | Count |
|---|---|
| 14 – 16 | 1 |
| 16 – 18 | 2 |
| 18 – 20 | 3 |
| 20 – 22 | 3 |
| 22 – 24 | 5 |
| 24 – 26 | 20 |
| 26 – 28 | 25 |
| 28 – 30 | 23 |
| 30 – 32 | 25 |
| 32 – 34 | 28 |
| 34 – 36 | 34 |
| 36 – 38 | 22 |
| 38 – 40 | 17 |
| 40 – 42 | 18 |
| 42 – 44 | 7 |
| 44 – 46 | 6 |
| 46 – 48 | 0 |
| 48 – 50 | 1 |
Box plot and violin
| region (Milliseconds) | Count | Lowest | First quartile | Median | Third quartile | Highest | Outliers |
|---|---|---|---|---|---|---|---|
| North | 41 | 89 | 112 | 119 | 128 | 144 | 260 |
| South | 40 | 109 | 132 | 144.5 | 152.25 | 174 | |
| East | 41 | 136 | 157 | 172 | 185 | 200 | 330 |
| West | 40 | 140 | 171.5 | 191.5 | 212.25 | 234 |
| region (ms) | Count | Lowest | First quartile | Median | Third quartile | Highest | Outliers |
|---|---|---|---|---|---|---|---|
| North | 41 | 89 | 112 | 119 | 128 | 144 | 260 |
| South | 40 | 109 | 132 | 144.5 | 152.25 | 174 | |
| East | 41 | 136 | 157 | 172 | 185 | 200 | 330 |
| West | 40 | 140 | 171.5 | 191.5 | 212.25 | 234 |
Fan chart
- Observed
- Forecast (median)
- 90% interval
- 50% interval
| Week | Observed | Forecast (median) | 90% interval | 50% interval |
|---|---|---|---|---|
| 1 | 108 | |||
| 2 | 111 | |||
| 3 | 110 | |||
| 4 | 107 | |||
| 5 | 109 | |||
| 6 | 116 | |||
| 7 | 125 | |||
| 8 | 130 | |||
| 9 | 129 | |||
| 10 | 127 | |||
| 11 | 127 | |||
| 12 | 133 | |||
| 13 | 142 | |||
| 14 | 148 | 142 | 142 – 142 | 142 – 142 |
| 15 | 144.6 | 139.1 – 150.6 | 142 – 147.4 | |
| 16 | 147.2 | 136.2 – 159.2 | 142 – 152.8 | |
| 17 | 149.8 | 133.3 – 167.8 | 142 – 158.2 | |
| 18 | 152.4 | 130.4 – 176.4 | 142 – 163.6 | |
| 19 | 155 | 127.5 – 185 | 142 – 169 | |
| 20 | 157.6 | 124.6 – 193.6 | 142 – 174.4 | |
| 21 | 160.2 | 121.7 – 202.2 | 142 – 179.8 | |
| 22 | 162.8 | 118.8 – 210.8 | 142 – 185.2 | |
| 23 | 165.4 | 115.9 – 219.4 | 142 – 190.6 | |
| 24 | 168 | 113 – 228 | 142 – 196 |
Small multiples
- North
- South
- East
- West
- Centre
- Coast
| region | Month | Visits |
|---|---|---|
| North | 1 | 46 |
| North | 2 | 51 |
| North | 3 | 52 |
| North | 4 | 50 |
| North | 5 | 45 |
| North | 6 | 38 |
| North | 7 | 31 |
| North | 8 | 25 |
| North | 9 | 21 |
| North | 10 | 21 |
| North | 11 | 24 |
| North | 12 | 29 |
| South | 1 | 59 |
| South | 2 | 63 |
| South | 3 | 63 |
| South | 4 | 60 |
| South | 5 | 55 |
| South | 6 | 50 |
| South | 7 | 46 |
| South | 8 | 44 |
| South | 9 | 46 |
| South | 10 | 51 |
| South | 11 | 59 |
| South | 12 | 67 |
| East | 1 | 65 |
| East | 2 | 64 |
| East | 3 | 59 |
| East | 4 | 52 |
| East | 5 | 44 |
| East | 6 | 38 |
| East | 7 | 34 |
| East | 8 | 34 |
| East | 9 | 37 |
| East | 10 | 42 |
| East | 11 | 48 |
| East | 12 | 54 |
| West | 1 | 72 |
| West | 2 | 69 |
| West | 3 | 64 |
| West | 4 | 59 |
| West | 5 | 55 |
| West | 6 | 53 |
| West | 7 | 55 |
| West | 8 | 60 |
| West | 9 | 68 |
| West | 10 | 76 |
| West | 11 | 84 |
| West | 12 | 89 |
| Centre | 1 | 72 |
| Centre | 2 | 65 |
| Centre | 3 | 57 |
| Centre | 4 | 51 |
| Centre | 5 | 47 |
| Centre | 6 | 47 |
| Centre | 7 | 50 |
| Centre | 8 | 55 |
| Centre | 9 | 62 |
| Centre | 10 | 67 |
| Centre | 11 | 71 |
| Centre | 12 | 71 |
| Coast | 1 | 73 |
| Coast | 2 | 68 |
| Coast | 3 | 64 |
| Coast | 4 | 62 |
| Coast | 5 | 64 |
| Coast | 6 | 69 |
| Coast | 7 | 77 |
| Coast | 8 | 85 |
| Coast | 9 | 93 |
| Coast | 10 | 98 |
| Coast | 11 | 100 |
| Coast | 12 | 99 |
Bars to 100 percent
- Web
- App
- Shop
| quarter | Web | App | Shop |
|---|---|---|---|
| Q1 | 320 (49.2%) | 210 (32.3%) | 120 (18.5%) |
| Q2 | 360 (48.6%) | 270 (36.5%) | 110 (14.9%) |
| Q3 | 400 (48.2%) | 330 (39.8%) | 100 (12%) |
| Q4 | 440 (47.8%) | 390 (42.4%) | 90 (9.8%) |
Treemap
| Part | Value | Share |
|---|---|---|
| Housing / Rent | 1,200 | 43.6% |
| Housing / Power | 140 | 5.1% |
| Housing / Water | 60 | 2.2% |
| Housing / Repairs | 90 | 3.3% |
| Food / Groceries | 420 | 15.3% |
| Food / Cafés | 90 | 3.3% |
| Food / Takeaway | 70 | 2.5% |
| Travel / Transit pass | 110 | 4% |
| Travel / Bike | 30 | 1.1% |
| Travel / Trains | 120 | 4.4% |
| Leisure / Books | 40 | 1.5% |
| Leisure / Music | 25 | 0.9% |
| Leisure / Sport | 55 | 2% |
| Savings | 300 | 10.9% |
Top
Sunburst
| Part | Value | Share |
|---|---|---|
| Housing / Rent | 1,200 | 43.6% |
| Housing / Power | 140 | 5.1% |
| Housing / Water | 60 | 2.2% |
| Housing / Repairs | 90 | 3.3% |
| Food / Groceries | 420 | 15.3% |
| Food / Cafés | 90 | 3.3% |
| Food / Takeaway | 70 | 2.5% |
| Travel / Transit pass | 110 | 4% |
| Travel / Bike | 30 | 1.1% |
| Travel / Trains | 120 | 4.4% |
| Leisure / Books | 40 | 1.5% |
| Leisure / Music | 25 | 0.9% |
| Leisure / Sport | 55 | 2% |
| Savings | 300 | 10.9% |
- Housing54.2%
- Food21.1%
- Travel9.5%
- Leisure4.4%
- Savings10.9%
Circle packing
| Part | Value | Share |
|---|---|---|
| Housing / Rent | 1,200 | 43.6% |
| Housing / Power | 140 | 5.1% |
| Housing / Water | 60 | 2.2% |
| Housing / Repairs | 90 | 3.3% |
| Food / Groceries | 420 | 15.3% |
| Food / Cafés | 90 | 3.3% |
| Food / Takeaway | 70 | 2.5% |
| Travel / Transit pass | 110 | 4% |
| Travel / Bike | 30 | 1.1% |
| Travel / Trains | 120 | 4.4% |
| Leisure / Books | 40 | 1.5% |
| Leisure / Music | 25 | 0.9% |
| Leisure / Sport | 55 | 2% |
| Savings | 300 | 10.9% |
Sankey
| From | To | Amount |
|---|---|---|
| Salary | Budget | 2,400 |
| Freelance | Budget | 600 |
| Budget | Rent | 1,200 |
| Budget | Food | 600 |
| Budget | Travel | 300 |
| Budget | Saved | 900 |
Network graph
- App
- Library
- Tool
| Node | Group | Linked to |
|---|---|---|
| App | App | Ui, Charts, Maps, Forms, Three, Tests |
| Ui | Library | App, Theme, Icons, Motion, Forms |
| Charts | Library | App, Maths, Theme |
| Maps | Library | App, Maths, Theme |
| Maths | Library | Charts, Maps |
| Motion | Library | Ui, Theme |
| Three | Tool | Theme, App |
| Theme | Tool | Ui, Charts, Maps, Motion, Three |
| Icons | Tool | Ui |
| Dates | Tool | Forms |
| Forms | Tool | App, Ui, Dates |
| Tests | Tool | App |
Calendar heatmap
| day | Workouts |
|---|---|
| 2026-01-01 | 4 |
| 2026-01-02 | 8 |
| 2026-01-03 | 2 |
| 2026-01-04 | 2 |
| 2026-01-08 | 9 |
| 2026-01-09 | 5 |
| 2026-01-13 | 8 |
| 2026-01-15 | 11 |
| 2026-01-17 | 2 |
| 2026-01-18 | 4 |
| 2026-01-19 | 6 |
| 2026-01-21 | 10 |
| 2026-01-23 | 7 |
| 2026-01-24 | 3 |
| 2026-01-25 | 3 |
| 2026-01-26 | 8 |
| 2026-01-27 | 7 |
| 2026-01-29 | 10 |
| 2026-01-30 | 9 |
| 2026-02-01 | 3 |
| 2026-02-02 | 11 |
| 2026-02-03 | 4 |
| 2026-02-04 | 7 |
| 2026-02-05 | 8 |
| 2026-02-06 | 7 |
| 2026-02-08 | 2 |
| 2026-02-09 | 6 |
| 2026-02-11 | 4 |
| 2026-02-12 | 6 |
| 2026-02-13 | 6 |
| 2026-02-14 | 2 |
| 2026-02-15 | 2 |
| 2026-02-16 | 7 |
| 2026-02-21 | 4 |
| 2026-02-22 | 4 |
| 2026-02-25 | 11 |
| 2026-02-26 | 4 |
| 2026-02-27 | 5 |
| 2026-03-02 | 7 |
| 2026-03-03 | 6 |
| 2026-03-04 | 4 |
| 2026-03-05 | 10 |
| 2026-03-06 | 11 |
| 2026-03-08 | 3 |
| 2026-03-11 | 6 |
| 2026-03-13 | 6 |
| 2026-03-16 | 6 |
| 2026-03-18 | 8 |
| 2026-03-20 | 4 |
| 2026-03-21 | 2 |
| 2026-03-23 | 12 |
| 2026-03-24 | 12 |
| 2026-03-25 | 9 |
| 2026-03-27 | 10 |
| 2026-03-28 | 1 |
| 2026-03-29 | 3 |
| 2026-03-30 | 6 |
| 2026-04-01 | 5 |
| 2026-04-02 | 9 |
| 2026-04-03 | 5 |
| 2026-04-04 | 3 |
| 2026-04-06 | 5 |
| 2026-04-07 | 9 |
| 2026-04-09 | 10 |
| 2026-04-10 | 9 |
| 2026-04-13 | 6 |
| 2026-04-14 | 10 |
| 2026-04-16 | 11 |
| 2026-04-17 | 10 |
| 2026-04-19 | 4 |
| 2026-04-21 | 5 |
| 2026-04-23 | 6 |
| 2026-04-25 | 2 |
| 2026-04-26 | 2 |
| 2026-04-28 | 12 |
| 2026-04-29 | 5 |
| 2026-04-30 | 9 |
| 2026-05-03 | 1 |
| 2026-05-04 | 12 |
| 2026-05-05 | 8 |
| 2026-05-07 | 5 |
| 2026-05-08 | 8 |
| 2026-05-10 | 4 |
| 2026-05-12 | 5 |
| 2026-05-13 | 5 |
| 2026-05-15 | 8 |
| 2026-05-16 | 3 |
| 2026-05-17 | 2 |
| 2026-05-18 | 11 |
| 2026-05-20 | 9 |
| 2026-05-21 | 8 |
| 2026-05-22 | 4 |
| 2026-05-23 | 2 |
| 2026-05-28 | 7 |
| 2026-05-29 | 10 |
| 2026-05-31 | 2 |
| 2026-06-02 | 10 |
| 2026-06-05 | 4 |
| 2026-06-06 | 3 |
| 2026-06-07 | 2 |
| 2026-06-08 | 8 |
| 2026-06-11 | 5 |
| 2026-06-12 | 4 |
| 2026-06-13 | 3 |
| 2026-06-14 | 1 |
| 2026-06-15 | 11 |
| 2026-06-16 | 4 |
| 2026-06-19 | 7 |
| 2026-06-22 | 4 |
| 2026-06-23 | 9 |
| 2026-06-24 | 5 |
| 2026-06-25 | 7 |
| 2026-06-28 | 2 |
| 2026-06-29 | 5 |
| 2026-06-30 | 10 |
Gantt chart
| Task | Group | Start | End | Done | After |
|---|---|---|---|---|---|
| Research | Product | Mar 2, 2026 | Mar 10, 2026 | 100% | |
| Design | Product | Mar 9, 2026 | Mar 20, 2026 | 100% | Research |
| Build | Product | Mar 16, 2026 | Apr 10, 2026 | 45% | Design |
| Test | Product | Apr 6, 2026 | Apr 17, 2026 | 0% | Build |
| Write the story | Marketing | Mar 23, 2026 | Apr 3, 2026 | 60% | |
| Update the site | Marketing | Apr 6, 2026 | Apr 14, 2026 | 0% | Write the story |
| Launch | Marketing | Apr 20, 2026 | Milestone | Test, Update the site |
Density
| # | Distance (km) | Fare |
|---|---|---|
| 1 | 1.4 | 3.9 |
| 2 | 1.5 | 4.1 |
| 3 | 1.5 | 5.5 |
| 4 | 1.5 | 5.9 |
| 5 | 1.6 | 4.2 |
| 6 | 1.6 | 6.2 |
| 7 | 1.6 | 6.9 |
| 8 | 1.7 | 4.3 |
| 9 | 1.7 | 6.1 |
| 10 | 1.7 | 6.3 |
| 11 | 1.7 | 7.2 |
| 12 | 1.7 | 7.7 |
| 13 | 1.8 | 5.9 |
| 14 | 1.8 | 6.1 |
| 15 | 1.8 | 6.4 |
| 16 | 1.8 | 6.5 |
| 17 | 1.8 | 7 |
| 18 | 1.9 | 5.5 |
| 19 | 1.9 | 7.5 |
| 20 | 2 | 5.5 |
| 21 | 2 | 7.8 |
| 22 | 2.1 | 4.4 |
| 23 | 2.1 | 4.9 |
| 24 | 2.1 | 6.6 |
| 25 | 2.1 | 7 |
| 26 | 2.1 | 7.5 |
| 27 | 2.1 | 7.8 |
| 28 | 2.1 | 8 |
| 29 | 2.1 | 8.6 |
| 30 | 2.2 | 5.4 |
| 31 | 2.2 | 7 |
| 32 | 2.2 | 7.5 |
| 33 | 2.2 | 7.6 |
| 34 | 2.2 | 7.8 |
| 35 | 2.2 | 7.8 |
| 36 | 2.2 | 7.9 |
| 37 | 2.2 | 8 |
| 38 | 2.2 | 8.1 |
| 39 | 2.2 | 8.2 |
| 40 | 2.2 | 8.7 |
| 41 | 2.2 | 8.9 |
| 42 | 2.3 | 6 |
| 43 | 2.3 | 6.7 |
| 44 | 2.3 | 7 |
| 45 | 2.3 | 7.8 |
| 46 | 2.3 | 8.2 |
| 47 | 2.3 | 8.2 |
| 48 | 2.3 | 8.5 |
| 49 | 2.3 | 9 |
| 50 | 2.4 | 6.7 |
| 51 | 2.4 | 6.8 |
| 52 | 2.4 | 7.7 |
| 53 | 2.4 | 8 |
| 54 | 2.4 | 8.1 |
| 55 | 2.4 | 8.2 |
| 56 | 2.4 | 9.3 |
| 57 | 2.5 | 5.6 |
| 58 | 2.5 | 5.8 |
| 59 | 2.5 | 6.7 |
| 60 | 2.5 | 7 |
| 61 | 2.5 | 7.3 |
| 62 | 2.5 | 7.5 |
| 63 | 2.5 | 8.1 |
| 64 | 2.5 | 8.3 |
| 65 | 2.5 | 8.5 |
| 66 | 2.5 | 8.5 |
| 67 | 2.5 | 10.8 |
| 68 | 2.5 | 10.9 |
| 69 | 2.6 | 7.3 |
| 70 | 2.6 | 7.8 |
| 71 | 2.6 | 7.9 |
| 72 | 2.6 | 8 |
| 73 | 2.6 | 8.2 |
| 74 | 2.6 | 9.6 |
| 75 | 2.6 | 9.7 |
| 76 | 2.6 | 9.9 |
| 77 | 2.6 | 10.6 |
| 78 | 2.7 | 7.8 |
| 79 | 2.7 | 8.4 |
| 80 | 2.7 | 8.5 |
| 81 | 2.7 | 9.1 |
| 82 | 2.8 | 6.4 |
| 83 | 2.8 | 7 |
| 84 | 2.8 | 7.2 |
| 85 | 2.8 | 7.5 |
| 86 | 2.8 | 7.7 |
| 87 | 2.8 | 8 |
| 88 | 2.8 | 8.4 |
| 89 | 2.8 | 8.6 |
| 90 | 2.8 | 9.3 |
| 91 | 2.8 | 9.6 |
| 92 | 2.8 | 9.6 |
| 93 | 2.8 | 9.7 |
| 94 | 2.8 | 9.8 |
| 95 | 2.8 | 9.9 |
| 96 | 2.8 | 10.4 |
| 97 | 2.9 | 8.1 |
| 98 | 2.9 | 8.4 |
| 99 | 2.9 | 8.7 |
| 100 | 2.9 | 8.7 |
| 101 | 2.9 | 8.9 |
| 102 | 2.9 | 9.2 |
| 103 | 2.9 | 9.3 |
| 104 | 2.9 | 9.5 |
| 105 | 2.9 | 9.7 |
| 106 | 2.9 | 9.7 |
| 107 | 2.9 | 9.8 |
| 108 | 2.9 | 9.9 |
| 109 | 3 | 8.1 |
| 110 | 3 | 8.4 |
| 111 | 3 | 8.6 |
| 112 | 3 | 9.7 |
| 113 | 3 | 9.9 |
| 114 | 3 | 10.2 |
| 115 | 3 | 10.9 |
| 116 | 3.1 | 7.9 |
| 117 | 3.1 | 8.4 |
| 118 | 3.1 | 8.8 |
| 119 | 3.1 | 8.8 |
| 120 | 3.1 | 9 |
| 121 | 3.1 | 9.4 |
| 122 | 3.1 | 9.4 |
| 123 | 3.1 | 10.1 |
| 124 | 3.1 | 10.2 |
| 125 | 3.1 | 10.3 |
| 126 | 3.1 | 10.3 |
| 127 | 3.1 | 10.3 |
| 128 | 3.2 | 7.7 |
| 129 | 3.2 | 8.8 |
| 130 | 3.2 | 8.9 |
| 131 | 3.2 | 9.3 |
| 132 | 3.2 | 9.4 |
| 133 | 3.2 | 9.5 |
| 134 | 3.2 | 9.5 |
| 135 | 3.2 | 9.5 |
| 136 | 3.2 | 9.5 |
| 137 | 3.2 | 9.6 |
| 138 | 3.2 | 9.9 |
| 139 | 3.2 | 9.9 |
| 140 | 3.2 | 10.1 |
| 141 | 3.2 | 10.4 |
| 142 | 3.2 | 11.1 |
| 143 | 3.2 | 11.4 |
| 144 | 3.2 | 11.5 |
| 145 | 3.3 | 9 |
| 146 | 3.3 | 9.1 |
| 147 | 3.3 | 9.8 |
| 148 | 3.3 | 10 |
| 149 | 3.3 | 10 |
| 150 | 3.3 | 10.3 |
| 151 | 3.3 | 10.3 |
| 152 | 3.3 | 10.4 |
| 153 | 3.3 | 10.5 |
| 154 | 3.3 | 10.6 |
| 155 | 3.3 | 11 |
| 156 | 3.3 | 11.2 |
| 157 | 3.3 | 11.5 |
| 158 | 3.4 | 9.5 |
| 159 | 3.4 | 10.5 |
| 160 | 3.4 | 11.1 |
| 161 | 3.4 | 11.2 |
| 162 | 3.4 | 11.3 |
| 163 | 3.4 | 11.6 |
| 164 | 3.5 | 9.1 |
| 165 | 3.5 | 9.3 |
| 166 | 3.5 | 10.1 |
| 167 | 3.5 | 11.5 |
| 168 | 3.6 | 8.3 |
| 169 | 3.6 | 10.7 |
| 170 | 3.6 | 10.9 |
| 171 | 3.6 | 11.9 |
| 172 | 3.7 | 8.8 |
| 173 | 3.7 | 9.2 |
| 174 | 3.7 | 9.3 |
| 175 | 3.7 | 9.6 |
| 176 | 3.7 | 10.6 |
| 177 | 3.7 | 11 |
| 178 | 3.7 | 11.1 |
| 179 | 3.7 | 11.3 |
| 180 | 3.7 | 12 |
| 181 | 3.7 | 12.4 |
| 182 | 3.7 | 12.7 |
| 183 | 3.8 | 10.6 |
| 184 | 3.8 | 11 |
| 185 | 3.8 | 11.1 |
| 186 | 3.8 | 11.5 |
| 187 | 3.8 | 11.5 |
| 188 | 3.8 | 11.7 |
| 189 | 3.8 | 12.1 |
| 190 | 3.8 | 12.1 |
| 191 | 3.8 | 13.3 |
| 192 | 3.8 | 13.5 |
| 193 | 3.9 | 9.1 |
| 194 | 3.9 | 9.2 |
| 195 | 3.9 | 9.9 |
| 196 | 3.9 | 10 |
| 197 | 3.9 | 11.5 |
| 198 | 3.9 | 11.6 |
| 199 | 4 | 9.8 |
| 200 | 4 | 10.7 |
| 201 | 4 | 11.6 |
| 202 | 4 | 12.1 |
| 203 | 4.1 | 9.7 |
| 204 | 4.1 | 11.5 |
| 205 | 4.1 | 11.9 |
| 206 | 4.2 | 10.1 |
| 207 | 4.2 | 10.9 |
| 208 | 4.2 | 11.4 |
| 209 | 4.2 | 11.6 |
| 210 | 4.2 | 11.9 |
| 211 | 4.2 | 13.9 |
| 212 | 4.4 | 11 |
| 213 | 4.4 | 12.3 |
| 214 | 4.5 | 12.1 |
| 215 | 4.6 | 12.2 |
| 216 | 4.6 | 13.5 |
| 217 | 4.7 | 11.4 |
| 218 | 4.7 | 12.9 |
| 219 | 4.9 | 12.4 |
| 220 | 5 | 15.1 |
| 221 | 8 | 19.6 |
| 222 | 8.5 | 20 |
| 223 | 8.6 | 21.4 |
| 224 | 8.6 | 22.7 |
| 225 | 8.9 | 22.4 |
| 226 | 9 | 21.3 |
| 227 | 9.3 | 20 |
| 228 | 9.4 | 22 |
| 229 | 9.7 | 22.4 |
| 230 | 9.7 | 22.7 |
| 231 | 9.8 | 22.9 |
| 232 | 9.8 | 24.1 |
| 233 | 9.8 | 24.2 |
| 234 | 9.9 | 23.9 |
| 235 | 9.9 | 24.4 |
| 236 | 9.9 | 24.6 |
| 237 | 9.9 | 25.3 |
| 238 | 10 | 23.7 |
| 239 | 10.1 | 23.2 |
| 240 | 10.1 | 23.2 |
| 241 | 10.2 | 22.5 |
| 242 | 10.3 | 24.3 |
| 243 | 10.3 | 24.3 |
| 244 | 10.3 | 24.5 |
| 245 | 10.5 | 24.4 |
| 246 | 10.8 | 26 |
| 247 | 10.9 | 25.5 |
| 248 | 10.9 | 25.7 |
| 249 | 11 | 24.6 |
| 250 | 11 | 27 |
| 251 | 11 | 27.7 |
| 252 | 11.1 | 24.5 |
| 253 | 11.1 | 24.9 |
| 254 | 11.1 | 25.6 |
| 255 | 11.1 | 25.9 |
| 256 | 11.1 | 26 |
| 257 | 11.1 | 26.8 |
| 258 | 11.2 | 26.4 |
| 259 | 11.2 | 26.6 |
| 260 | 11.2 | 26.8 |
| 261 | 11.3 | 25.5 |
| 262 | 11.3 | 25.8 |
| 263 | 11.3 | 27.4 |
| 264 | 11.4 | 25.2 |
| 265 | 11.4 | 27.3 |
| 266 | 11.4 | 28.1 |
| 267 | 11.4 | 28.1 |
| 268 | 11.5 | 25.8 |
| 269 | 11.5 | 26.3 |
| 270 | 11.5 | 27.4 |
| 271 | 11.6 | 28.6 |
| 272 | 11.6 | 28.9 |
| 273 | 11.7 | 26.5 |
| 274 | 11.7 | 26.6 |
| 275 | 11.7 | 27.5 |
| 276 | 11.7 | 28 |
| 277 | 11.8 | 27 |
| 278 | 11.8 | 27.1 |
| 279 | 11.9 | 25.6 |
| 280 | 11.9 | 26.3 |
| 281 | 11.9 | 27.7 |
| 282 | 11.9 | 29 |
| 283 | 12 | 27.2 |
| 284 | 12 | 27.3 |
| 285 | 12 | 28.7 |
| 286 | 12 | 29.2 |
| 287 | 12 | 30.1 |
| 288 | 12.1 | 29.8 |
| 289 | 12.1 | 30 |
| 290 | 12.2 | 27.2 |
| 291 | 12.2 | 27.4 |
| 292 | 12.3 | 28.1 |
| 293 | 12.3 | 29 |
| 294 | 12.4 | 29.4 |
| 295 | 12.5 | 27.1 |
| 296 | 12.5 | 29.1 |
| 297 | 12.5 | 30.5 |
| 298 | 12.6 | 28.3 |
| 299 | 12.6 | 29.2 |
| 300 | 12.7 | 28.6 |
| 301 | 12.8 | 29.3 |
| 302 | 12.8 | 29.5 |
| 303 | 12.9 | 28.8 |
| 304 | 12.9 | 28.8 |
| 305 | 12.9 | 29.8 |
| 306 | 12.9 | 30.1 |
| 307 | 12.9 | 31.1 |
| 308 | 12.9 | 32.3 |
| 309 | 13 | 30.2 |
| 310 | 13 | 31.2 |
| 311 | 13 | 31.9 |
| 312 | 13 | 32.4 |
| 313 | 13.1 | 29.5 |
| 314 | 13.1 | 31.9 |
| 315 | 13.2 | 30.7 |
| 316 | 13.2 | 31 |
| 317 | 13.3 | 29.6 |
| 318 | 13.3 | 30.6 |
| 319 | 13.3 | 32.1 |
| 320 | 13.3 | 32.6 |
| 321 | 13.5 | 30.5 |
| 322 | 13.5 | 31.8 |
| 323 | 13.6 | 29.9 |
| 324 | 13.6 | 31.8 |
| 325 | 13.7 | 30.6 |
| 326 | 13.7 | 31.1 |
| 327 | 13.7 | 32.4 |
| 328 | 13.8 | 32.7 |
| 329 | 13.9 | 32.4 |
| 330 | 14 | 32.8 |
| 331 | 14 | 34.7 |
| 332 | 14.1 | 31.1 |
| 333 | 14.1 | 33.7 |
| 334 | 14.2 | 31.7 |
| 335 | 14.2 | 33.4 |
| 336 | 14.4 | 32.7 |
| 337 | 14.8 | 33.6 |
| 338 | 14.9 | 32.6 |
| 339 | 14.9 | 35.4 |
| 340 | 15.1 | 34.5 |
Radar
- Basic
- Plus
- Pro
| measure | Basic | Plus | Pro |
|---|---|---|---|
| Speed | 3 | 4 | 5 |
| Storage | 2 | 4 | 5 |
| Support | 2 | 3 | 5 |
| Price | 5 | 4 | 2 |
| Security | 3 | 4 | 5 |
| Sharing | 2 | 5 | 4 |
Waterfall
| Step | Change | Running total |
|---|---|---|
| Revenue | 500 (Total) | 500 |
| Costs | -220 (Fall) | 280 |
| Marketing | -80 (Fall) | 200 |
| Other income | +30 (Rise) | 230 |
| Tax | -46 (Fall) | 184 |
| Profit | 184 (Total) | 184 |
Funnel
| Step | Count | of the first step | of the step before |
|---|---|---|---|
| Visited | 1,200 | 100% | |
| Started | 640 | 53.3% | 53.3% |
| Confirmed email | 410 | 34.2% | 64.1% |
| Finished | 290 | 24.2% | 70.7% |
Bullet
| Measure | Value | Target | Bands |
|---|---|---|---|
| Revenue | 270 | 250 | 150, 225, 300 |
| New customers | 1,400 | 1,600 | 1,000, 1,500, 2,000 |
| Satisfaction | 4.1 | 4.3 | 3, 4, 5 |
Candlestick
| Period | Open | High | Low | Close |
|---|---|---|---|---|
| Mar 2, 2026 | 40 | 40.5 | 38.2 | 39.4 |
| Mar 3, 2026 | 39.4 | 40.8 | 39 | 39.7 |
| Mar 4, 2026 | 39.7 | 42.3 | 39.4 | 41.3 |
| Mar 5, 2026 | 41.3 | 41.4 | 39.2 | 40.2 |
| Mar 6, 2026 | 40.2 | 40.8 | 38.1 | 39 |
| Mar 7, 2026 | 39 | 40.7 | 38.6 | 40.1 |
| Mar 8, 2026 | 40.1 | 40.5 | 39.1 | 39.8 |
| Mar 9, 2026 | 39.8 | 40.1 | 38.6 | 39.7 |
| Mar 10, 2026 | 39.7 | 40.3 | 39.4 | 39.4 |
| Mar 11, 2026 | 39.4 | 40.5 | 39.1 | 40.2 |
| Mar 12, 2026 | 40.2 | 41.2 | 38.8 | 39.4 |
| Mar 13, 2026 | 39.4 | 41.5 | 38.3 | 40.8 |
| Mar 14, 2026 | 40.8 | 41.3 | 40.4 | 41.1 |
| Mar 15, 2026 | 41.1 | 41.7 | 40.8 | 41.5 |
| Mar 16, 2026 | 41.5 | 42.6 | 40.5 | 40.8 |
| Mar 17, 2026 | 40.8 | 41.7 | 39.9 | 40.2 |
| Mar 18, 2026 | 40.2 | 41.4 | 39.2 | 40.5 |
| Mar 19, 2026 | 40.5 | 41.2 | 39.5 | 41.1 |
| Mar 20, 2026 | 41.1 | 41.1 | 40.1 | 40.8 |
| Mar 21, 2026 | 40.8 | 42 | 40.3 | 41.7 |
| Mar 22, 2026 | 41.7 | 41.9 | 40.7 | 40.7 |
| Mar 23, 2026 | 40.7 | 42.5 | 40.7 | 41.9 |
| Mar 24, 2026 | 41.9 | 42.7 | 40.5 | 40.7 |
| Mar 25, 2026 | 40.7 | 40.8 | 39.6 | 39.8 |
| Mar 26, 2026 | 39.8 | 42.3 | 39 | 41.4 |
| Mar 27, 2026 | 41.4 | 41.5 | 41.1 | 41.1 |
| Mar 28, 2026 | 41.1 | 42 | 40.4 | 40.6 |
| Mar 29, 2026 | 40.6 | 40.8 | 39.5 | 40.1 |
| Mar 30, 2026 | 40.1 | 41.6 | 39 | 41.1 |
| Mar 31, 2026 | 41.1 | 41.9 | 40.3 | 40.5 |
Chord diagram
| From | To | Amount |
|---|---|---|
| North | South | 120 |
| North | East | 40 |
| North | West | 30 |
| North | Centre | 60 |
| South | North | 80 |
| South | East | 60 |
| South | West | 20 |
| South | Centre | 40 |
| East | North | 30 |
| East | South | 90 |
| East | West | 50 |
| East | Centre | 70 |
| West | North | 20 |
| West | South | 30 |
| West | East | 40 |
| West | Centre | 35 |
| Centre | North | 55 |
| Centre | South | 45 |
| Centre | East | 65 |
| Centre | West | 30 |
Parallel coordinates
- Power
- Light
- Value
| name | kind | Price | Weight (kg) | Battery (h) | Screen (in) |
|---|---|---|---|---|---|
| Model A | Power | 1,221 | 1.1 | 12 | 16.6 |
| Model B | Light | 1,466 | 1.8 | 13 | 15.6 |
| Model C | Value | 915 | 2.4 | 7 | 16.9 |
| Model D | Power | 1,596 | 1.9 | 12 | 15.5 |
| Model E | Light | 742 | 1.3 | 8 | 15.1 |
| Model F | Value | 1,454 | 1.2 | 7 | 15.8 |
| Model G | Power | 884 | 1.9 | 11 | 16 |
| Model H | Light | 707 | 1.3 | 17 | 14.3 |
| Model I | Value | 766 | 2 | 13 | 15.4 |
| Model J | Power | 1,253 | 1 | 8 | 14 |
| Model K | Light | 1,349 | 1.1 | 8 | 13.8 |
| Model L | Value | 1,500 | 1.8 | 11 | 14.6 |
| Model M | Power | 1,783 | 2.2 | 14 | 14.4 |
| Model N | Light | 1,604 | 2 | 13 | 14.5 |
Dot plot
- Before
- After
| team | Before | After |
|---|---|---|
| Support | 62 | 78 |
| Sales | 70 | 74 |
| Product | 55 | 71 |
| Finance | 66 | 63 |
| Design | 72 | 81 |
| # | region | Milliseconds |
|---|---|---|
| 15 | North | 89 |
| 25 | North | 90 |
| 27 | North | 93 |
| 37 | North | 99 |
| 23 | North | 100 |
| 29 | North | 105 |
| 40 | North | 105 |
| 16 | North | 107 |
| 12 | North | 108 |
| 31 | North | 108 |
| 14 | North | 112 |
| 17 | North | 112 |
| 18 | North | 112 |
| 33 | North | 113 |
| 38 | North | 113 |
| 19 | North | 114 |
| 21 | North | 116 |
| 5 | North | 117 |
| 35 | North | 117 |
| 1 | North | 119 |
| 7 | North | 119 |
| 22 | North | 120 |
| 4 | North | 121 |
| 24 | North | 121 |
| 13 | North | 125 |
| 3 | North | 126 |
| 6 | North | 126 |
| 9 | North | 126 |
| 11 | North | 126 |
| 34 | North | 126 |
| 32 | North | 128 |
| 28 | North | 129 |
| 2 | North | 130 |
| 36 | North | 130 |
| 26 | North | 131 |
| 30 | North | 132 |
| 39 | North | 132 |
| 8 | North | 136 |
| 20 | North | 140 |
| 10 | North | 144 |
| 161 | North | 260 |
| 63 | South | 109 |
| 77 | South | 113 |
| 57 | South | 115 |
| 78 | South | 117 |
| 80 | South | 123 |
| 71 | South | 129 |
| 42 | South | 131 |
| 69 | South | 131 |
| 43 | South | 132 |
| 46 | South | 132 |
| 74 | South | 132 |
| 48 | South | 134 |
| 68 | South | 136 |
| 45 | South | 138 |
| 76 | South | 139 |
| 50 | South | 140 |
| 58 | South | 140 |
| 59 | South | 140 |
| 67 | South | 142 |
| 51 | South | 144 |
| 44 | South | 145 |
| 72 | South | 145 |
| 75 | South | 145 |
| 55 | South | 146 |
| 66 | South | 146 |
| 64 | South | 147 |
| 62 | South | 148 |
| 49 | South | 150 |
| 60 | South | 150 |
| 52 | South | 152 |
| 65 | South | 153 |
| 41 | South | 154 |
| 56 | South | 154 |
| 54 | South | 158 |
| 61 | South | 158 |
| 73 | South | 158 |
| 79 | South | 159 |
| 70 | South | 172 |
| 53 | South | 173 |
| 47 | South | 174 |
| 90 | East | 136 |
| 108 | East | 144 |
| 118 | East | 144 |
| 84 | East | 147 |
| 81 | East | 149 |
| 114 | East | 149 |
| 93 | East | 150 |
| 107 | East | 153 |
| 110 | East | 154 |
| 109 | East | 156 |
| 112 | East | 157 |
| 85 | East | 161 |
| 92 | East | 163 |
| 94 | East | 164 |
| 89 | East | 167 |
| 86 | East | 168 |
| 88 | East | 168 |
| 96 | East | 168 |
| 113 | East | 169 |
| 99 | East | 170 |
| 104 | East | 172 |
| 97 | East | 173 |
| 102 | East | 173 |
| 103 | East | 174 |
| 91 | East | 175 |
| 119 | East | 176 |
| 95 | East | 178 |
| 100 | East | 178 |
| 87 | East | 180 |
| 101 | East | 180 |
| 98 | East | 185 |
| 115 | East | 185 |
| 120 | East | 185 |
| 111 | East | 187 |
| 82 | East | 193 |
| 83 | East | 193 |
| 105 | East | 193 |
| 116 | East | 194 |
| 106 | East | 196 |
| 117 | East | 200 |
| 162 | East | 330 |
| 140 | West | 140 |
| 126 | West | 141 |
| 145 | West | 149 |
| 146 | West | 150 |
| 136 | West | 156 |
| 131 | West | 160 |
| 144 | West | 165 |
| 134 | West | 167 |
| 149 | West | 168 |
| 137 | West | 170 |
| 138 | West | 172 |
| 143 | West | 178 |
| 124 | West | 179 |
| 123 | West | 183 |
| 156 | West | 186 |
| 157 | West | 186 |
| 125 | West | 187 |
| 151 | West | 187 |
| 133 | West | 189 |
| 135 | West | 190 |
| 141 | West | 193 |
| 147 | West | 193 |
| 128 | West | 195 |
| 127 | West | 200 |
| 129 | West | 204 |
| 121 | West | 206 |
| 130 | West | 206 |
| 148 | West | 206 |
| 139 | West | 209 |
| 154 | West | 212 |
| 132 | West | 213 |
| 155 | West | 213 |
| 160 | West | 215 |
| 153 | West | 219 |
| 150 | West | 221 |
| 159 | West | 222 |
| 122 | West | 224 |
| 152 | West | 225 |
| 142 | West | 226 |
| 158 | West | 234 |
Stream
- Jazz
- Folk
- Rock
- Electronic
| year | Jazz | Folk | Rock | Electronic |
|---|---|---|---|---|
| 2,015 | 20 | 30 | 53 | 15 |
| 2,016 | 26 | 34 | 50 | 18 |
| 2,017 | 29 | 37 | 45 | 21 |
| 2,018 | 28 | 38 | 41 | 24 |
| 2,019 | 27 | 37 | 40 | 27 |
| 2,020 | 29 | 35 | 41 | 30 |
| 2,021 | 34 | 31 | 41 | 33 |
| 2,022 | 40 | 27 | 38 | 36 |
| 2,023 | 44 | 24 | 34 | 39 |
| 2,024 | 44 | 22 | 29 | 42 |
| 2,025 | 43 | 22 | 27 | 45 |
| 2,026 | 44 | 24 | 28 | 48 |
Slope
| mode | 2016 | 2026 | Change |
|---|---|---|---|
| Car | 52 | 41 | -11 (Fell) |
| Bike | 9 | 18 | +9 (Rose) |
| Transit | 24 | 27 | +3 (Rose) |
| Walking | 13 | 12 | -1 (Fell) |
Brush
| day | Visits |
|---|---|
| May 1, 2026 | 334 |
| May 2, 2026 | 348 |
| May 3, 2026 | 344 |
| May 4, 2026 | 344 |
| May 5, 2026 | 331 |
| May 6, 2026 | 324 |
| May 7, 2026 | 326 |
| May 8, 2026 | 334 |
| May 9, 2026 | 328 |
| May 10, 2026 | 322 |
| May 11, 2026 | 313 |
| May 12, 2026 | 306 |
| May 13, 2026 | 311 |
| May 14, 2026 | 309 |
| May 15, 2026 | 289 |
| May 16, 2026 | 289 |
| May 17, 2026 | 287 |
| May 18, 2026 | 290 |
| May 19, 2026 | 285 |
| May 20, 2026 | 262 |
| May 21, 2026 | 279 |
| May 22, 2026 | 279 |
| May 23, 2026 | 265 |
| May 24, 2026 | 288 |
| May 25, 2026 | 278 |
| May 26, 2026 | 282 |
| May 27, 2026 | 283 |
| May 28, 2026 | 289 |
| May 29, 2026 | 303 |
| May 30, 2026 | 307 |
| May 31, 2026 | 315 |
| Jun 1, 2026 | 313 |
| Jun 2, 2026 | 335 |
| Jun 3, 2026 | 337 |
| Jun 4, 2026 | 345 |
| Jun 5, 2026 | 352 |
| Jun 6, 2026 | 363 |
| Jun 7, 2026 | 381 |
| Jun 8, 2026 | 351 |
| Jun 9, 2026 | 378 |
| Jun 10, 2026 | 354 |
| Jun 11, 2026 | 372 |
| Jun 12, 2026 | 371 |
| Jun 13, 2026 | 363 |
| Jun 14, 2026 | 366 |
| Jun 15, 2026 | 360 |
| Jun 16, 2026 | 350 |
| Jun 17, 2026 | 355 |
| Jun 18, 2026 | 347 |
| Jun 19, 2026 | 342 |
| Jun 20, 2026 | 339 |
| Jun 21, 2026 | 336 |
| Jun 22, 2026 | 303 |
| Jun 23, 2026 | 301 |
| Jun 24, 2026 | 317 |
| Jun 25, 2026 | 317 |
| Jun 26, 2026 | 313 |
| Jun 27, 2026 | 315 |
| Jun 28, 2026 | 308 |
| Jun 29, 2026 | 304 |
120–179
Add it
npx shadcn@latest add @rivier-ui/dot-plot
The registry is named once in components.json: see Installation.
Example
Import it from @/components/viz/dot-plot.
<DotPlot
label="Satisfaction before and after"
data={[
{ team: "Support", before: 62, after: 78 },
{ team: "Sales", before: 70, after: 74 },
{ team: "Product", before: 55, after: 71 },
]}
y="team"
series={[{ key: "before", label: "Before" }, { key: "after", label: "After" }]}
variant="dumbbell"
/>
What it needs
A client component: it uses state, effects or browser behaviour. Packages: d3-scale.
It imports
It is used by
Source
The whole file. Once copied it is yours: the registry item holds the same text.
"use client";
/**
* @name dot-plot
* @category viz
* @description Values as dots along a shared axis, one row per category: plain dots for one or more series, a lollipop (a stick to the dot), a dumbbell (two values joined, for a before and after), or a beeswarm (every single value as its own dot, packed so none overlap).
* @when Comparing values across categories with less ink than bars, especially when zero is not meaningful (dot, dumbbell), showing a change between two moments per category (dumbbell), or showing every observation in a few groups (beeswarm). For totals from zero use bar-chart; for a summary of spread use box-plot.
* @example
* <DotPlot
* label="Satisfaction before and after"
* data={[
* { team: "Support", before: 62, after: 78 },
* { team: "Sales", before: 70, after: 74 },
* { team: "Product", before: 55, after: 71 },
* ]}
* y="team"
* series={[{ key: "before", label: "Before" }, { key: "after", label: "After" }]}
* variant="dumbbell"
* />
*/
import { scaleBand } from "d3-scale";
import { useMemo } from "react";
import { cn } from "@/lib/cn";
import {
axisNumberFormatter,
ChartAxis,
ChartContainer,
ChartEmpty,
ChartGrid,
ChartLegend,
ChartMark,
chartLinear,
chartSeries,
ChartSvg,
ChartTooltip,
fitText,
formatNumber,
readNumber,
useChartCursor,
widestText,
type ChartBaseProps,
type ChartSeries,
} from "@/components/viz/chart";
export type DotPlotProps<T extends object> = ChartBaseProps & {
data: readonly T[];
/** The field naming each row: a category, or a group in a beeswarm. */
y: keyof T & string;
/** The values. A lollipop and a beeswarm use the first; a dumbbell joins the first two. */
series: readonly ChartSeries<T>[];
variant?: "dot" | "lollipop" | "dumbbell" | "beeswarm";
/** Start the axis at zero. Default: true for a lollipop, false otherwise. */
zero?: boolean;
/** A field naming each dot in a beeswarm, for the tooltip and the table. */
name?: keyof T & string;
showGrid?: boolean;
showLegend?: boolean;
};
type Row = { name: string; values: (number | null)[] };
type Swarm = { group: number; value: number; name: string; offset: number };
/** Packs dots of radius r along x so none overlap, each as close to its row's centre line as it can be. */
function dodge(values: { value: number; px: number; index: number }[], r: number): Map<number, number> {
const placed: { px: number; offset: number }[] = [];
const offsets = new Map<number, number>();
for (const item of [...values].sort((a, b) => a.px - b.px)) {
let offset = 0;
for (let step = 0; step < 400; step++) {
const candidate = step === 0 ? 0 : Math.ceil(step / 2) * (step % 2 ? 1 : -1) * r * 0.5;
if (placed.every((p) => Math.hypot(p.px - item.px, p.offset - candidate) >= r * 2)) {
offset = candidate;
break;
}
}
placed.push({ px: item.px, offset });
offsets.set(item.index, offset);
}
return offsets;
}
export function DotPlot<T extends object>({
data,
y,
series,
variant = "dot",
zero,
name,
showGrid = true,
showLegend,
label,
aspect,
height,
emptyLabel,
locale,
formatValue,
className,
...props
}: DotPlotProps<T>) {
const swarm = variant === "beeswarm";
const used = variant === "lollipop" || swarm ? series.slice(0, 1) : variant === "dumbbell" ? series.slice(0, 2) : series;
const model = useMemo(() => {
const read = (row: T, key: string): string => String((row as Record<string, unknown>)[key] ?? "");
if (swarm) {
const groups = [...new Set(data.map((row) => read(row, y)))];
const first = used[0];
const dots: Swarm[] = first
? data.flatMap((row, index) => {
const value = readNumber(row, first.key);
return value === null ? [] : [{ group: groups.indexOf(read(row, y)), value, name: name ? read(row, name) : String(index + 1), offset: 0 }];
})
: [];
dots.sort((a, b) => a.group - b.group || a.value - b.value);
return { rows: groups.map((g): Row => ({ name: g, values: [] })), dots };
}
return { rows: data.map((row): Row => ({ name: read(row, y), values: used.map((s) => readNumber(row, s.key)) })), dots: [] as Swarm[] };
}, [data, y, used, swarm, name]);
const { rows, dots } = model;
const cursor = useChartCursor(swarm ? dots.length : rows.length);
const number = formatValue ?? ((value: number) => formatNumber(value, locale));
const table = swarm
? { caption: label, columns: [name ?? "#", y, used[0]?.label ?? ""], rows: dots.map((d) => [d.name, rows[d.group]?.name ?? "", number(d.value)]) }
: { caption: label, columns: [y, ...used.map((s) => s.label)], rows: rows.map((row) => [row.name, ...row.values.map((v) => (v === null ? "" : number(v)))]) };
const rowReading = (row: Row): { label: string; value: string; index: number }[] =>
used.flatMap((s, i) => (row.values[i] === null || row.values[i] === undefined ? [] : [{ label: s.label, value: number(row.values[i] as number), index: i }]));
const currentRow = !swarm && cursor.active !== null ? rows[cursor.active] : undefined;
const currentDot = swarm && cursor.active !== null ? dots[cursor.active] : undefined;
const announcement = !cursor.keyboard
? ""
: currentRow
? `${currentRow.name}: ${rowReading(currentRow)
.map((r) => `${r.label} ${r.value}`)
.join(", ")}`
: currentDot
? `${currentDot.name}, ${rows[currentDot.group]?.name ?? ""}: ${number(currentDot.value)}`
: "";
const legend = showLegend ?? (!swarm && used.length > 1);
const fromZero = zero ?? variant === "lollipop";
return (
<div data-slot="dot-plot" className={cn("flex w-full min-w-0 flex-col gap-3", className)} {...props}>
{legend ? <ChartLegend items={used.map((s, i) => ({ label: s.label, index: i }))} mark="rect" /> : null}
<ChartContainer aspect={aspect} height={height ?? Math.max(120, rows.length * (swarm ? 72 : 36) + 36)} table={table} announcement={announcement}>
{({ width, height: plotHeight }) => {
const values = swarm ? dots.map((d) => d.value) : rows.flatMap((row) => row.values.filter((v): v is number => v !== null));
if (values.length === 0) return <ChartEmpty>{emptyLabel}</ChartEmpty>;
const bottom = 26;
const nameRoom = Math.min(Math.round(width * 0.3), widestText(rows.map((r) => r.name)) + 12);
const sx = chartLinear(Math.min(...values, ...(fromZero ? [0] : [])), Math.max(...values, ...(fromZero ? [0] : [])), [nameRoom, width - 12], 80);
const axis = formatValue ?? axisNumberFormatter(Math.max(...values.map(Math.abs)), locale);
const band = scaleBand<number>()
.domain(rows.map((_, i) => i))
.range([4, plotHeight - bottom])
.paddingInner(0.1);
const mid = (i: number): number => (band(i) ?? 0) + band.bandwidth() / 2;
const r = swarm ? Math.max(2.5, Math.min(5, band.bandwidth() / 10)) : 5;
// Each row is packed on its own, so dots of one group never push those of another.
const offsets = new Map<number, number>();
if (swarm) {
rows.forEach((_, g) => {
const mine = dots.flatMap((d, index) => (d.group === g ? [{ value: d.value, px: sx.scale(d.value), index }] : []));
for (const [index, offset] of dodge(mine, r)) offsets.set(index, offset);
});
}
const offsetOf = (index: number): number => Math.max(-band.bandwidth() / 2 + r, Math.min(band.bandwidth() / 2 - r, offsets.get(index) ?? 0));
const tip =
currentRow && cursor.active !== null
? { x: sx.scale(Math.max(...currentRow.values.filter((v): v is number => v !== null))), y: mid(cursor.active) }
: currentDot && cursor.active !== null
? { x: sx.scale(currentDot.value), y: mid(currentDot.group) + offsetOf(cursor.active) }
: undefined;
return (
<>
<ChartSvg label={label} width={width} height={plotHeight} interactive {...cursor.svgProps}>
{showGrid ? <ChartGrid offsets={sx.ticks.map((t) => sx.scale(t))} from={4} to={plotHeight - bottom} vertical /> : null}
<ChartAxis side="bottom" at={plotHeight - bottom + 6} ticks={sx.ticks.map((t) => ({ offset: sx.scale(t), label: axis(t) }))} />
<ChartAxis side="left" at={nameRoom - 8} ticks={rows.map((row, i) => ({ offset: mid(i), label: fitText(row.name, nameRoom - 12) }))} />
<g aria-hidden="true">
{!swarm
? rows.map((row, i) => {
const present = row.values.map((v, s) => ({ v, s })).filter((item): item is { v: number; s: number } => item.v !== null);
const dim = cursor.active !== null && cursor.active !== i;
return (
<g key={i} onPointerEnter={() => cursor.point(i)} className={cn("transition-opacity duration-instant motion-reduce:transition-none", dim && "opacity-40")}>
<rect x={0} y={band(i) ?? 0} width={width} height={band.bandwidth()} fill="transparent" />
<line x1={nameRoom} x2={width - 12} y1={mid(i)} y2={mid(i)} className="stroke-border" strokeDasharray="1 3" />
{variant === "lollipop" && present[0] ? (
<line x1={sx.scale(0)} x2={sx.scale(present[0].v)} y1={mid(i)} y2={mid(i)} className={chartSeries(0).stroke} strokeWidth={2} />
) : null}
{variant === "dumbbell" && present.length === 2 ? (
<line x1={sx.scale(present[0]?.v ?? 0)} x2={sx.scale(present[1]?.v ?? 0)} y1={mid(i)} y2={mid(i)} className="stroke-muted-foreground" strokeWidth={2.5} />
) : null}
{present.map((item) => (
<ChartMark key={item.s} index={item.s} x={sx.scale(item.v)} y={mid(i)} radius={r} />
))}
</g>
);
})
: dots.map((d, i) => (
<circle
key={i}
cx={sx.scale(d.value)}
cy={mid(d.group) + offsetOf(i)}
r={r}
className={cn(
chartSeries(0).fill,
"stroke-background transition-opacity duration-instant motion-reduce:transition-none",
cursor.active !== null && cursor.active !== i && "opacity-50",
)}
strokeWidth={1}
onPointerEnter={() => cursor.point(i)}
/>
))}
{tip ? <circle cx={tip.x} cy={tip.y} r={r + 3} fill="none" className="stroke-foreground" strokeWidth={2} /> : null}
</g>
</ChartSvg>
{tip && currentRow ? (
<ChartTooltip x={tip.x} y={tip.y} side={tip.x > width / 2 ? "left" : "right"} title={currentRow.name} rows={rowReading(currentRow).map((row) => ({ ...row, mark: "rect" as const }))} />
) : null}
{tip && currentDot ? (
<ChartTooltip
x={tip.x}
y={tip.y}
side={tip.x > width / 2 ? "left" : "right"}
title={currentDot.name}
rows={[{ label: rows[currentDot.group]?.name ?? "", value: number(currentDot.value) }]}
/>
) : null}
</>
);
}}
</ChartContainer>
</div>
);
}