Demo
Polar and radar charts
Documented in Chart.
Polar and radar charts
Wind speed by direction on polar circles or radar polygons, drawn as lines, areas, wedges or points, stacked or not, from any start angle.
Column chart: Wind by direction, 3 series, x from N to NW. Calm: 8 points, minimum 2, maximum 4, trending up. Speed: 8 points, minimum 8, maximum 16, trending up. Gust: 8 points, minimum 14, maximum 24, trending up.
| x | Calm | Speed | Gust |
|---|---|---|---|
| N | 2 | 8 | 14 |
| NE | 3 | 13 | 21 |
| E | 4 | 9 | 17 |
| SE | 2 | 14 | 24 |
| S | 3 | 10 | 20 |
| SW | 4 | 15 | 16 |
| W | 2 | 11 | 23 |
| NW | 3 | 16 | 19 |
Demo.tsx
'use client';
import { useState } from 'react';
import { Chart } from '@salmonui/charts/chart';
import { polar } from '@salmonui/charts/chart/features';
import { Checkbox } from '@salmonui/inputs/checkbox';
import { Slider } from '@salmonui/inputs/slider';
import { Select } from '@salmonui/dropdowns/select';
const wind = ['N', 'NE', 'E', 'SE', 'S', 'SW', 'W', 'NW'].map((direction, i) => ({
direction,
speed: 8 + ((i * 5) % 9),
gust: 14 + ((i * 7) % 11),
calm: 2 + (i % 3),
}));
type DrawType = 'line' | 'area' | 'column' | 'scatter';
export default function ChartPolarDemo() {
const [coordinate, setCoordinate] = useState<'polar' | 'radar'>('polar');
const [drawType, setDrawType] = useState<DrawType>('column');
const [stacked, setStacked] = useState(false);
const [startAngle, setStartAngle] = useState(0);
return (
<div className="demo-stack">
<div className="demo-toolbar">
<label>
Coordinate
<Select aria-label="Coordinate" data={['polar', 'radar']} value={coordinate} onValueChange={(value) => value != null && setCoordinate(value as 'polar' | 'radar')} />
</label>
<label>
Series type
<Select aria-label="Series type" data={['line', 'area', 'column', 'scatter']} value={drawType} onValueChange={(value) => value != null && setDrawType(value as DrawType)} />
</label>
<Checkbox checked={stacked} onCheckedChange={(checked) => setStacked(checked)}>
Stacked
</Checkbox>
<Slider label="Start angle" min={0} max={315} step={45} value={startAngle} onValueChange={setStartAngle} style={{ inlineSize: 160 }} />
</div>
<Chart
title="Wind by direction"
coordinate={coordinate}
features={[polar]}
xAxis={{ startAngle }}
radius={0.9}
data={wind}
height={380}
series={[
{ type: drawType, name: 'Calm', xField: 'direction', yField: 'calm', stack: stacked || undefined },
{ type: drawType, name: 'Speed', xField: 'direction', yField: 'speed', stack: stacked || undefined },
{ type: drawType, name: 'Gust', xField: 'direction', yField: 'gust', stack: stacked || undefined },
]}
/>
</div>
);
}
coordinate switches between 'polar' (circles) and 'radar'
(polygons); the series type picks how each series is drawn, stack gives
the stacking variants and xAxis.startAngle rotates the first category.
The polar layout is the opt-in polar feature from
@salmonui/charts/chart/features, passed in features, so it renders on
the server too.