Demo
Waterfall, histogram, box plot, Pareto and error bars
Documented in Chart.
Waterfall, histogram, box plot, Pareto and error bars
The statistical Chart series: a profit bridge with subtotals and totals, a histogram with a normal curve, box plots with three quartile methods, a Pareto chart and columns with five kinds of error bars.
Waterfall chart: Profit bridge, 1 series, x from Revenue to Net profit. Amount: 7 points, minimum -180, maximum 420, trending down.
| x | Amount |
|---|---|
| Revenue | $420 |
| Cost of sales | -$180 |
| Gross profit | $240 |
| Marketing | -$60 |
| R&D | -$75 |
| Other income | $25 |
| Net profit | $130 |
Histogram chart: Response times, 1 series, x from 100 to 300. Requests: 200 points, minimum 119, maximum 337, trending down.
| x | Requests |
|---|---|
| 0 | 220 |
| 1 | 249 |
| 2 | 229 |
| 3 | 292 |
| 4 | 225 |
| 5 | 298 |
| 6 | 209 |
| 7 | 266 |
| 8 | 191 |
| 9 | 217 |
| 10 | 189 |
| 11 | 179 |
| 12 | 213 |
| 13 | 172 |
| 14 | 254 |
| 15 | 195 |
| 16 | 291 |
| 17 | 230 |
| 18 | 301 |
| 19 | 256 |
| 20 | 274 |
| 21 | 263 |
| 22 | 223 |
| 23 | 253 |
| 24 | 176 |
| 25 | 242 |
| 26 | 160 |
| 27 | 241 |
| 28 | 185 |
| 29 | 251 |
| 30 | 239 |
| 31 | 261 |
| 32 | 292 |
| 33 | 258 |
| 34 | 318 |
| 35 | 238 |
| 36 | 304 |
| 37 | 211 |
| 38 | 264 |
| 39 | 197 |
| 40 | 222 |
| 41 | 210 |
| 42 | 202 |
| 43 | 250 |
| 44 | 210 |
| 45 | 297 |
| 46 | 235 |
| 47 | 325 |
| 48 | 259 |
| 49 | 316 |
| 50 | 268 |
| 51 | 272 |
| 52 | 263 |
| 53 | 216 |
| 54 | 255 |
| 55 | 180 |
| 56 | 256 |
| 57 | 184 |
| 58 | 270 |
| 59 | 224 |
| 60 | 285 |
| 61 | 278 |
| 62 | 287 |
| 63 | 316 |
| 64 | 267 |
| 65 | 321 |
| 66 | 232 |
| 67 | 295 |
| 68 | 203 |
| 69 | 256 |
| 70 | 201 |
| 71 | 229 |
| 72 | 232 |
| 73 | 225 |
| 74 | 283 |
| 75 | 239 |
| 76 | 326 |
| 77 | 257 |
| 78 | 337 |
| 79 | 265 |
| 80 | 307 |
| 81 | 259 |
| 82 | 252 |
| 83 | 251 |
| 84 | 202 |
| 85 | 253 |
| 86 | 183 |
| 87 | 269 |
| 88 | 204 |
| 89 | 292 |
| 90 | 250 |
| 91 | 302 |
| 92 | 295 |
| 93 | 288 |
| 94 | 314 |
| 95 | 250 |
| 96 | 302 |
| 97 | 208 |
| 98 | 272 |
| 99 | 187 |
| 100 | 243 |
| 101 | 202 |
| 102 | 232 |
| 103 | 248 |
| 104 | 238 |
| 105 | 302 |
| 106 | 250 |
| 107 | 332 |
| 108 | 253 |
| 109 | 322 |
| 110 | 245 |
| 111 | 276 |
| 112 | 232 |
| 113 | 220 |
| 114 | 231 |
| 115 | 184 |
| 116 | 248 |
| 117 | 184 |
| 118 | 277 |
| 119 | 216 |
| 120 | 299 |
| 121 | 258 |
| 122 | 296 |
| 123 | 286 |
| 124 | 263 |
| 125 | 287 |
| 126 | 213 |
| 127 | 267 |
| 128 | 174 |
| 129 | 242 |
| 130 | 169 |
| 131 | 229 |
| 132 | 202 |
| 133 | 231 |
| 134 | 257 |
| 135 | 239 |
| 136 | 302 |
| 137 | 239 |
| 138 | 313 |
| 139 | 225 |
| 140 | 284 |
| 141 | 206 |
| 142 | 232 |
| 143 | 197 |
| 144 | 185 |
| 145 | 210 |
| 146 | 166 |
| 147 | 242 |
| 148 | 182 |
| 149 | 277 |
| 150 | 216 |
| 151 | 290 |
| 152 | 246 |
| 153 | 268 |
| 154 | 256 |
| 155 | 219 |
| 156 | 245 |
| 157 | 167 |
| 158 | 227 |
| 159 | 140 |
| 160 | 216 |
| 161 | 155 |
| 162 | 218 |
| 163 | 202 |
| 164 | 226 |
| 165 | 256 |
| 166 | 226 |
| 167 | 286 |
| 168 | 210 |
| 169 | 277 |
| 170 | 183 |
| 171 | 236 |
| 172 | 164 |
| 173 | 188 |
| 174 | 167 |
| 175 | 157 |
| 176 | 198 |
| 177 | 156 |
| 178 | 241 |
| 179 | 179 |
| 180 | 271 |
| 181 | 206 |
| 182 | 267 |
| 183 | 220 |
| 184 | 228 |
| 185 | 216 |
| 186 | 170 |
| 187 | 204 |
| 188 | 126 |
| 189 | 197 |
| 190 | 119 |
| 191 | 202 |
| 192 | 152 |
| 193 | 214 |
| 194 | 205 |
| 195 | 219 |
| 196 | 248 |
| 197 | 204 |
| 198 | 260 |
| 199 | 173 |
Box plot chart: Weekly hours per team. No data.
| x | Hours |
|---|---|
| Alpha | min 30, Q1 30, median 30, Q3 37, max 37 |
| Beta | min 33, Q1 35, median 39, Q3 43, max 45 |
| Gamma | min 36, Q1 38, median 42, Q3 46, max 48 |
| Delta | min 39, Q1 41, median 45, Q3 49, max 59 |
Pareto chart: Defects by cause, 1 series, x from Scratches to Other. Defects: 6 points, minimum 5, maximum 46, trending down.
| x | Defects |
|---|---|
| Scratches | 46 |
| Missing screw | 27 |
| Dent | 19 |
| Misalignment | 12 |
| Wrong part | 8 |
| Other | 5 |
Column chart: Effect by dose, 1 series, x from Placebo to 40 mg. Effect: 4 points, minimum 12, maximum 41, trending up.
| x | Effect |
|---|---|
| Placebo | 12 |
| 10 mg | 21 |
| 20 mg | 34 |
| 40 mg | 41 |
Demo.tsx
'use client';
import { useState } from 'react';
import { Select } from '@salmonui/dropdowns/select';
import { Chart } from '@salmonui/charts/chart';
import type { ChartErrorBars } from '@salmonui/charts/chart';
const cashFlow = [
{ step: 'Revenue', amount: 420 },
{ step: 'Cost of sales', amount: -180 },
{ step: 'Gross profit', amount: 0 },
{ step: 'Marketing', amount: -60 },
{ step: 'R&D', amount: -75 },
{ step: 'Other income', amount: 25 },
{ step: 'Net profit', amount: 0 },
];
// 200 response times (ms) from a deterministic, roughly normal mix.
const responses = Array.from({ length: 200 }, (_, i) => ({ ms: Math.round(220 + 40 * (Math.sin(i * 12.9898) + Math.sin(i * 78.233) + Math.sin(i * 37.719))) }));
const teams = ['Alpha', 'Beta', 'Gamma', 'Delta'].map((team, t) => ({
team,
hours: Array.from({ length: 15 }, (_, i) => 30 + t * 3 + ((i * (7 + t)) % 14) + (i === 3 ? 18 : 0)),
}));
const defects = [
{ cause: 'Misalignment', count: 12 },
{ cause: 'Scratches', count: 46 },
{ cause: 'Wrong part', count: 8 },
{ cause: 'Missing screw', count: 27 },
{ cause: 'Dent', count: 19 },
{ cause: 'Other', count: 5 },
];
const trials = [
{ dose: 'Placebo', effect: 12, plus: 4, minus: 3 },
{ dose: '10 mg', effect: 21, plus: 5, minus: 4 },
{ dose: '20 mg', effect: 34, plus: 6, minus: 6 },
{ dose: '40 mg', effect: 41, plus: 9, minus: 5 },
];
type ErrorKind = ChartErrorBars['kind'];
export default function ChartStatisticalDemo() {
const [quartile, setQuartile] = useState<'exclusive' | 'inclusive' | 'normal'>('exclusive');
const [binWidth, setBinWidth] = useState(20);
const [errorKind, setErrorKind] = useState<ErrorKind>('custom');
return (
<div className="demo-stack">
<Chart
title="Profit bridge"
data={cashFlow}
height={280}
yAxis={{ format: 'c0' }}
legend={false}
series={[{ type: 'waterfall', name: 'Amount', xField: 'step', yField: 'amount', subtotals: [2], totals: [6], connectors: true, labels: true }]}
/>
<div className="demo-toolbar">
<label>
Bin width (ms)
<Select aria-label="Bin width (ms)" data={[{ value: 10, label: '10' }, { value: 20, label: '20' }, { value: 40, label: '40' }]} value={binWidth} onValueChange={(value) => value != null && setBinWidth(Number(value))} />
</label>
</div>
<Chart title="Response times" data={responses} height={260} legend={false} series={[{ type: 'histogram', name: 'Requests', yField: 'ms', binWidth, normalCurve: true }]} />
<div className="demo-toolbar">
<label>
Quartile method
<Select aria-label="Quartile method" data={[{ value: 'exclusive', label: 'exclusive' }, { value: 'inclusive', label: 'inclusive' }, { value: 'normal', label: 'normal' }]} value={quartile} onValueChange={(value) => value != null && setQuartile(value as 'exclusive' | 'inclusive' | 'normal')} />
</label>
</div>
<Chart
title="Weekly hours per team"
data={teams}
height={280}
legend={false}
series={[{ type: 'boxPlot', name: 'Hours', xField: 'team', yField: 'hours', quartileMethod: quartile, mean: true, outliers: true }]}
/>
<Chart title="Defects by cause" data={defects} height={280} series={[{ type: 'pareto', name: 'Defects', xField: 'cause', yField: 'count', pareto: { line: true, markers: true } }]} />
<div className="demo-toolbar">
<label>
Error bar kind
<Select aria-label="Error bar kind" data={[{ value: 'custom', label: 'custom (plus / minus fields)' }, { value: 'fixed', label: 'fixed (3)' }, { value: 'percent', label: 'percent (15)' }, { value: 'standardDeviation', label: 'standardDeviation' }, { value: 'standardError', label: 'standardError' }]} value={errorKind} onValueChange={(value) => value != null && setErrorKind(value as ErrorKind)} />
</label>
</div>
<Chart
title="Effect by dose"
data={trials}
height={260}
legend={false}
series={[
{
type: 'column',
name: 'Effect',
xField: 'dose',
yField: 'effect',
errorBars: { kind: errorKind, amount: errorKind === 'percent' ? 15 : errorKind === 'fixed' ? 3 : 1, plusField: 'plus', minusField: 'minus', caps: true },
},
]}
/>
</div>
);
}
- Waterfall:
subtotals: [2]andtotals: [6]mark the bars computed from the steps before them;connectorsjoins the bars. - Histogram: bins of
binWidthms over the raw values, withnormalCurve. - Box plot:
yFieldholds an array per team; switchquartileMethodand see the boxes move.meandraws the mean marker andoutliersthe points beyond the whiskers. - Pareto: sorted columns plus the cumulative percent line on a generated secondary axis.
- Error bars:
errorBars.kind'custom'readsplusField/minusField;'fixed','percent','standardDeviation'and'standardError'compute the whiskers.