@chartgpu/chartgpu

中文文档
0.4.0发布于 2026/08/03MITTypeScriptES Module零依赖近 30 天下载 4173

High-performance WebGPU charting library

原始使用文档
文档目录11 节
  1. Overview
  2. Demo
  3. Install
  4. Minimal example
  5. Features
  6. Series types
  7. Multi-chart (shared device)
  8. Browser support
  9. Documentation
  10. Contributing
  11. License

ChartGPU

WebGPU charting library for large datasets, real-time streaming, multi-chart dashboards, and 3D series. MIT licensed. Zero npm runtime dependencies.

npm tests MIT docs demo Featured in Awesome WebGPU

Live demo · Docs · API · Examples


Overview

ChartGPU renders charts with WebGPU (not Canvas2D or WebGL). It is aimed at:

  • Dense time series and multi-million-point series
  • Streaming updates (appendData with optional ring capacity)
  • Shared-device multi-chart dashboards
  • 2D series plus cartesian3d (pointCloud3d, surface3d)

There is no WebGL/Canvas fallback. Unsupported browsers must be gated by the host app.


Demo

ChartGPU demo

Streaming multi-chart wall (shared GPU device):

Streaming multi-chart dashboard

Streaming dashboards · Multi-chart cookbook · Live examples

Scatter densityCandlestick / OHLCAnnotations
Scatter densityCandlestickAnnotations

Install

npm install @chartgpu/chartgpu

Also published as unscoped chartgpu (same version line). React bindings: chartgpu-react (npm i chartgpu-react @chartgpu/chartgpu).

Minimal example

import { ChartGPU } from '@chartgpu/chartgpu';

const el = document.getElementById('chart')!;
const chart = await ChartGPU.create(el, {
  series: [{
    type: 'line',
    data: {
      x: new Float64Array([0, 1, 2]),
      y: new Float64Array([1, 3, 2]),
    },
  }],
});

// Prefer column-shaped x/y at scale; object/[x,y] tuples are fine for small demos
const x = new Float64Array([3, 4, 5]);
const y = new Float64Array([2.5, 2.1, 2.8]);
chart.appendData(0, { x, y }, { maxPoints: 50_000 });

Requires a WebGPU-capable browser (see Browser support).


Features

  • Streaming — appendData with optional maxPoints ring (FIFO). Heatmap and 3D surfaces use dedicated update APIs (updateHeatmap, updateSurface3D) rather than full option rewrites every tick.
  • Sampling — LTTB / min / max on the CPU; eligible line series can run decimation on the GPU. Nulls create gaps; optional connectNulls. performance.lod: auto | strict.
  • Multi-chart — Share one GPUDevice and pipeline cache across charts (≥3 recommended). Zoom sync via connectCharts.
  • Interaction — Zoom, pan, multi-axis Y scales, dark/light/custom themes, annotations.
  • 3D — coordinateSystem: 'cartesian3d' with pointCloud3d and surface3d.
  • Dependencies — Zero npm runtime dependencies. MIT license for commercial embedding.

Architecture notes: docs/ARCHITECTURE.md. Performance guide: chartgpu.io/docs/performance. Theming: chartgpu.io/docs/theming.


Series types

Full options: API — options.

CategoryTypes / modesDocs
Cartesianline, area, bar, scatter, pieline · scatter
Financecandlestick, ohlccandlestick
Scientificheatmap, band, errorBar, impulseheatmap
Variantsstep line/area · stacked mountain · scatter mode: 'density'charting
3DpointCloud3d, surface3d3D API

Multi-chart (shared device)

For three or more charts on one page, create a single adapter/device/pipeline cache and pass it into each ChartGPU.create. Charts do not destroy a shared device on dispose.

import { ChartGPU, createPipelineCache, connectCharts } from '@chartgpu/chartgpu';

if (!navigator.gpu) {
  throw new Error('WebGPU not available');
}

const adapter = await navigator.gpu.requestAdapter({ powerPreference: 'high-performance' });
if (!adapter) throw new Error('No GPU adapter');

const device = await adapter.requestDevice();
const pipelineCache = createPipelineCache(device);
const ctx = { adapter, device, pipelineCache };

const a = await ChartGPU.create(document.getElementById('a')!, {
  series: [{ type: 'line', data: { x: new Float64Array([0]), y: new Float64Array([0]) } }],
}, ctx);
const b = await ChartGPU.create(document.getElementById('b')!, {
  series: [{ type: 'line', data: { x: new Float64Array([0]), y: new Float64Array([0]) } }],
}, ctx);
const c = await ChartGPU.create(document.getElementById('c')!, {
  series: [{ type: 'line', data: { x: new Float64Array([0]), y: new Float64Array([0]) } }],
}, ctx);

connectCharts([a, b, c], { syncZoom: true });
// Optional: setRenderMode('external') + renderFrame() for a single app rAF loop

Recipes: multi-chart cookbook · streaming dashboards.


Browser support

WebGPU only. No WebGL path.

BrowserSupport
Chrome / Edge113+
Safari18+
FirefoxWindows 114+; macOS 145+; Linux incomplete — see gpuweb status

Detect navigator.gpu before creating charts. Do not leave an unsupported user on a blank canvas without UI.

If you need Canvas/SVG or dual WebGL+WebGPU backends, use a library that ships those fallbacks.


Documentation

ResourceDescription
Docs hubGuides and series docs
Getting startedInstall and first chart
API referencecreate, options, streaming, interaction, 3D
ChartingSeries, axes, interaction
Streaming dashboardsShared device, multi-chart
AnnotationsLines, markers, labels
PerformanceDensity, sampling, GPU sharing
ThemingDark / light / custom
ArchitectureRender path (repo)
InternalsContributors
examples/Local Vite samples
npm install
npm run dev
# open the examples URL printed by the dev server

Contributing

See CONTRIBUTING.md and docs/ARCHITECTURE.md.

License

MIT. Free for commercial use. No npm runtime dependencies.

版本与发布记录

@chartgpu/chartgpu 共发布 17 个版本,首次发布于 2026/02/11;过去 12 个月发布了 17 个版本。

版本发布日期距今
0.4.0latest2026/08/033 个月前
0.3.102026/08/013 个月前
0.3.92026/07/303 个月前
0.3.82026/07/303 个月前
0.3.72026/07/283 个月前
0.3.62026/07/223 个月前

关于 @chartgpu/chartgpu 的常见问题

@chartgpu/chartgpu 是什么?

High-performance WebGPU charting library

如何安装 @chartgpu/chartgpu?

在项目目录运行 npm install @chartgpu/chartgpu,或使用 pnpm add / yarn add / bun add。

@chartgpu/chartgpu 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@chartgpu/chartgpu 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@chartgpu/chartgpu 可以商用吗?

@chartgpu/chartgpu 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@chartgpu/chartgpu 的下载量有多少?

根据 npm 官方下载统计,@chartgpu/chartgpu 在 2026/10/10 – 2026/11/08 这 30 天内被下载 4,173 次,日均约 139 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@chartgpu/chartgpu 还在维护吗?

最新版本 0.4.0 发布于 2026/08/03(3 个月前);至今共发布 17 个版本,其中过去 12 个月发布了 17 个;首次发布于 2026/02/11。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。