Demo
Axis scales and ranges
Documented in Chart axes.
Axis scales and ranges
Time and time-category axes with calendar intervals, linear and log value axes, an indexed category axis with label placement, and axis ranges with includeZero, padding, min, max, interval and tickCount.
Line chart: Closing price, 1 series, x from Mar 2 to Mar 30. Close: 22 points, minimum 180, maximum 208.88, trending up.
| x | Close |
|---|---|
| Mar 2 | $180 |
| Mar 3 | $185 |
| Mar 4 | $189 |
| Mar 5 | $193 |
| Mar 6 | $196 |
| Mar 9 | $197 |
| Mar 10 | $197 |
| Mar 11 | $196 |
| Mar 12 | $193 |
| Mar 13 | $191 |
| Mar 16 | $188 |
| Mar 17 | $185 |
| Mar 18 | $183 |
| Mar 19 | $182 |
| Mar 20 | $182 |
| Mar 23 | $183 |
| Mar 24 | $186 |
| Mar 25 | $190 |
| Mar 26 | $195 |
| Mar 27 | $200 |
| Mar 30 | $204 |
| Mar 31 | $209 |
Line chart: Users per year, 1 series, x from 2016 to 2025. Users: 10 points, minimum 30, maximum 79,254, trending up.
| x | Users |
|---|---|
| 2016 | 30 |
| 2017 | 72 |
| 2018 | 173 |
| 2019 | 415 |
| 2020 | 995 |
| 2021 | 2,389 |
| 2022 | 5,733 |
| 2023 | 13,759 |
| 2024 | 33,023 |
| 2025 | 79,254 |
Column chart: Output per shift, 1 series, x from Mon to Tue. Output: 5 points, minimum 39, maximum 51, trending up.
| x | Output |
|---|---|
| Mon | 42 |
| Tue | 47 |
| Wed | 51 |
| Mon | 39 |
| Tue | 44 |
Demo.tsx
'use client';
import { useState } from 'react';
import { Checkbox } from '@salmonui/inputs/checkbox';
import { Select } from '@salmonui/dropdowns/select';
import { Chart } from '@salmonui/charts/chart';
// Trading days only (weekends missing): a 'time' axis shows the gaps, 'timeCategory' closes them.
const days = Array.from({ length: 30 }, (_, i) => new Date(Date.UTC(2026, 2, 2 + i))).filter((d) => d.getUTCDay() % 6 !== 0);
const closes = days.map((date, i) => ({ date, close: 180 + 12 * Math.sin(i / 3) + i }));
const growth = Array.from({ length: 10 }, (_, i) => ({ year: 2016 + i, users: Math.round(30 * 2.4 ** i) }));
// Two "Mon" categories: only indexed: true keeps them apart.
const shifts = [
{ day: 'Mon', output: 42 },
{ day: 'Tue', output: 47 },
{ day: 'Wed', output: 51 },
{ day: 'Mon', output: 39 },
{ day: 'Tue', output: 44 },
];
type Unit = 'day' | 'week';
type Padding = 'auto' | 'none' | 'normal' | 'additional' | 'round';
export default function ChartAxisScalesDemo() {
const [timeScale, setTimeScale] = useState<'time' | 'timeCategory'>('time');
const [unit, setUnit] = useState<Unit>('week');
const [valueScale, setValueScale] = useState<'linear' | 'log'>('log');
const [base, setBase] = useState(10);
const [includeZero, setIncludeZero] = useState(false);
const [padding, setPadding] = useState<Padding>('auto');
const [indexed, setIndexed] = useState(true);
const [placement, setPlacement] = useState<'between' | 'on'>('between');
return (
<div className="demo-stack">
<div className="demo-toolbar">
<label>
Date scale
<Select aria-label="Date scale" data={[{ value: 'time', label: 'time' }, { value: 'timeCategory', label: 'timeCategory' }]} value={timeScale} onValueChange={(value) => value != null && setTimeScale(value as 'time' | 'timeCategory')} />
</label>
<label>
Interval
<Select aria-label="Interval" data={[{ value: 'day', label: '2 days' }, { value: 'week', label: '1 week' }]} value={unit} onValueChange={(value) => value != null && setUnit(value as Unit)} disabled={timeScale !== 'time'} />
</label>
<Checkbox checked={includeZero} onCheckedChange={(checked) => setIncludeZero(checked)}>includeZero</Checkbox>
<label>
Padding
<Select aria-label="Padding" data={(['auto', 'none', 'normal', 'additional', 'round'] as const).map((p) => ({ value: p, label: p }))} value={padding} onValueChange={(value) => value != null && setPadding(value as Padding)} />
</label>
</div>
<Chart
title="Closing price"
data={closes}
height={240}
timeZone="UTC"
locale="en-US"
legend={false}
xAxis={{ scale: timeScale, interval: timeScale === 'time' ? (unit === 'day' ? { unit: 'day', step: 2 } : { unit: 'week', step: 1 }) : undefined, format: 'MMMd', labelOverlap: 'hide' }}
yAxis={{ includeZero, padding, format: 'c0' }}
series={[{ type: 'line', name: 'Close', xField: 'date', yField: 'close', markers: timeScale === 'timeCategory' }]}
/>
<div className="demo-toolbar">
<label>
Value scale
<Select aria-label="Value scale" data={[{ value: 'linear', label: 'linear' }, { value: 'log', label: 'log' }]} value={valueScale} onValueChange={(value) => value != null && setValueScale(value as 'linear' | 'log')} />
</label>
<label>
Log base
<Select aria-label="Log base" data={[{ value: 2, label: '2' }, { value: 10, label: '10' }]} value={base} onValueChange={(value) => value != null && setBase(Number(value))} disabled={valueScale !== 'log'} />
</label>
</div>
<Chart
title="Users per year"
data={growth}
height={240}
legend={false}
xAxis={{ scale: 'linear', min: 2016, max: 2025, interval: 1, formatLabel: (v) => String(v) }}
yAxis={{ scale: valueScale, base, format: 'n0' }}
series={[{ type: 'line', name: 'Users', xField: 'year', yField: 'users', markers: true }]}
/>
<div className="demo-toolbar">
<Checkbox checked={indexed} onCheckedChange={(checked) => setIndexed(checked)}>indexed</Checkbox>
<label>
Label placement
<Select aria-label="Label placement" data={[{ value: 'between', label: 'between' }, { value: 'on', label: 'on' }]} value={placement} onValueChange={(value) => value != null && setPlacement(value as 'between' | 'on')} />
</label>
</div>
<Chart
title="Output per shift"
data={shifts}
height={220}
legend={false}
xAxis={{ scale: 'category', indexed, labelPlacement: placement }}
yAxis={{ min: 0, max: 60, tickCount: 4 }}
series={[{ type: 'column', name: 'Output', xField: 'day', yField: 'output' }]}
/>
</div>
);
}
- The price chart has trading days only.
scale: 'time'keeps the weekend gaps and ticks on calendar boundaries (interval: { unit, step }, a date skeletonformat,timeZone="UTC");'timeCategory'closes the gaps.includeZeroandpaddingchange the value axis range. - The users chart switches its value axis between
'linear'(1-2-5 nice ticks) and'log'withbase2 or 10; its x axis is linear withmin,maxandinterval: 1. - The shift chart repeats "Mon" and "Tue":
indexedgives each point its own band, andlabelPlacementputs the labels between or on the ticks. Its value axis fixesmin,maxandtickCount.