chartgpu-react is a thin React + TypeScript wrapper around the @chartgpu/chartgpu WebGPU charting library.
npm install chartgpu-react @chartgpu/chartgpu react react-dom- React: 18+
- WebGPU: a browser with
navigator.gpusupport (Chrome/Edge 113+, Safari 18+)
If WebGPU is not available, chart creation will fail.
import { ChartGPU } from 'chartgpu-react';
import type { ChartGPUOptions } from 'chartgpu-react';
const options: ChartGPUOptions = {
series: [
{
type: 'line',
data: [
{ x: 0, y: 0 },
{ x: 1, y: 1 },
{ x: 2, y: 4 },
],
},
],
xAxis: { type: 'value' },
yAxis: { type: 'value' },
};
export function MyChart() {
return (
<ChartGPU
options={options}
style={{ width: '100%', height: 400 }}
theme="dark"
/>
);
}The chart renders into a container <div>. Make sure it has a non-zero height:
- Prefer
style={{ height: 400 }}or a CSS class with explicit height. - If the container height is
0, the chart may render blank even though it initialized.
The component and hook both attach a ResizeObserver and call chart.resize() (debounced).
- Replace options: updating the
optionsprop callschart.setOption(options)(full replacement, not a partial merge). - Stream/append: for realtime charts, prefer
ChartGPUHandle.appendData(...)instead of rebuildingoptions.series[].data.
See Streaming recipe.
In development, React 18 StrictMode intentionally runs effects twice (mount → unmount → mount). ChartGPU and useChartGPU are written to be safe under this behavior (async create + cleanup ordering).
- API reference
- Component details:
ChartGPU,ChartGPUHandle - Hooks:
useChartGPUanduseConnectCharts - Recipes: crosshair move, chart sync, annotation authoring, streaming, dataZoom basics, scatter density
- Troubleshooting and FAQ