开源图表引擎
自选列表
30 个币对,每行一个 24 小时迷你图,价格每 2 秒刷新。迷你图是同一个池里的图表,共用一个 GPU 设备,因此一个页面放很多小图也不会超出浏览器的 WebGL 上下文数量上限。
自选列表:价格走势示例
FerroChart.createPool · preset: 'sparkline' · theme object · addSeries('baseline')
代码
import { FerroChart } from '@ferrochart/core';
const canvas = document.querySelector('canvas');
// Market data: OKX spot (BTC, ETH, SOL against USDT) through the FerroChart demo API.
// A watchlist: 30 pairs, each row with a 24-hour sparkline. The sparklines
// come from one pool, so they share one GPU device (a page can hold only a
// few WebGL contexts); prices refresh every 2 seconds. A row opens its pair
// in the chart on the left.
const PAIRS = ['BTC', 'ETH', 'SOL', 'BNB', 'XRP', 'DOGE', 'ADA', 'AVAX', 'LINK', 'LTC', 'DOT', 'TRX', 'SHIB', 'BCH', 'NEAR',
'UNI', 'APT', 'ATOM', 'ETC', 'FIL', 'ARB', 'OP', 'SUI', 'PEPE', 'ICP', 'XLM', 'HBAR', 'AAVE', 'INJ', 'WLD'];
const UP = '#2ee6b6', DOWN = '#ff5d73';
const digits = (p) => (p >= 100 ? 2 : p >= 1 ? 3 : p >= 0.01 ? 5 : 8);
// The list: right of the chart, or below it on a narrow screen.
const narrow = canvas.parentElement.clientWidth < 640;
const list = document.createElement('div');
list.style.cssText = 'position:absolute;overflow-y:auto;background:#0b0d12;font:500 13px system-ui;color:#e6e9ef;'
+ (narrow ? 'left:0;right:0;bottom:0;height:55%;border-top:1px solid #ffffff14' : 'top:0;right:0;bottom:0;width:min(360px,48%);border-left:1px solid #ffffff14');
if (narrow) canvas.style.height = '45%';
else canvas.style.width = 'calc(100% - min(360px, 48%))';
const title = document.createElement('div');
title.style.cssText = 'position:absolute;left:16px;top:12px;font:600 15px system-ui;color:#e6e9ef;pointer-events:none';
canvas.after(list, title);
const chart = await FerroChart.create(canvas, { theme: 'dark' });
const main = chart.addSeries('area', { color: '#4cc9f0', topFill: '#4cc9f055', bottomFill: '#4cc9f000', lineWidth: 2 });
async function open(sym) {
const bars = await fetch(`/api/live/bars?symbol=${sym}USDT&interval=15m&count=672`).then((r) => r.json());
main.applyOptions({ pricePrecision: digits(bars.close.at(-1)) });
main.setData({ time: bars.time, value: bars.close });
chart.fitContent();
title.textContent = `${sym} / USDT · 15m`;
for (const row of list.children) row.style.boxShadow = row.dataset.sym === sym ? 'inset 3px 0 #4cc9f0' : '';
}
const pool = await FerroChart.createPool();
const rows = new Map();
for (const sym of PAIRS) {
const row = document.createElement('div');
row.dataset.sym = sym;
row.style.cssText = 'display:grid;grid-template-columns:64px 1fr 96px;align-items:center;gap:10px;padding:8px 14px;border-bottom:1px solid #ffffff0a;cursor:pointer';
row.innerHTML = `<b>${sym}</b><canvas style="width:100%;height:36px"></canvas>
<div style="text-align:right"><div class="p">—</div><div class="c" style="font-size:11px">—</div></div>`;
row.onclick = () => open(sym);
list.append(row);
const spark = await pool.create(row.querySelector('canvas'), { preset: 'sparkline', theme: { base: 'dark', background: '#0b0d12' } });
const s = spark.addSeries('baseline', { color: UP, downColor: DOWN, topFill: '#00000000', bottomFill: '#00000000', lineWidth: 1.5, lastValueVisible: false, priceLineVisible: false });
rows.set(sym, { row, spark, s, last: null });
}
// One day of 5-minute closes per pair, against the price 24 hours ago.
await Promise.all(PAIRS.map(async (sym) => {
const r = rows.get(sym);
const bars = await fetch(`/api/live/bars?symbol=${sym}USDT&interval=5m&count=288`).then((res) => (res.ok ? res.json() : null));
if (!bars) return;
r.s.applyOptions({ baseValue: bars.open[0] });
r.s.setData({ time: bars.time, value: bars.close });
r.spark.fitContent();
r.last = bars.time.at(-1);
}));
async function tick() {
const quotes = await fetch(`/api/live/tickers?symbols=${PAIRS.map((p) => `${p}USDT`).join(',')}`).then((r) => r.json()).catch(() => []);
for (const { symbol, price, ref } of quotes) {
const r = rows.get(symbol.replace(/USDT$/, ''));
if (!r) continue;
const pct = (price / ref - 1) * 100;
r.row.querySelector('.p').textContent = Number(price).toFixed(digits(price));
const c = r.row.querySelector('.c');
c.textContent = `${pct >= 0 ? '+' : ''}${pct.toFixed(2)}%`;
c.style.color = pct >= 0 ? UP : DOWN;
// The sparkline follows the price: the last 5-minute point, or a new one.
if (r.last === null) continue;
r.last = Math.max(r.last, Math.floor(Date.now() / 300_000) * 300_000);
r.s.update({ time: r.last, value: Number(price) });
}
}
await tick();
const timer = setInterval(tick, 2000);
await open('BTC');
const stop = () => clearInterval(timer); // then pool.destroy() and chart.destroy()为逐笔级数据而生。
Apple M4 Max · Chrome + WebGPU在浏览器中载入 100 万根 K 线并画出首帧
WASM · WebGPU
原生载入 1000 万根 K 线,含多级细节金字塔
原生 Rust
平移、缩放和实时推送时每帧的堆分配次数
稳定状态
WebAssembly 包体积(gzip)
包含全部功能
浏览器数据:Google Chrome + WebGPU;1000 万根 K 线的载入为原生 Rust。进度条表示各项数据相对于目标的比例:载入 300 毫秒、零分配、安装包 1.5 MB。
示例
313 个示例,
覆盖 20 个应用场景。
每个示例都是 FerroChart 在你的浏览器中实时渲染的图表,并附带源代码。所有数据均为模拟数据。



价格走势
25 个示例 →适用于任何市场的 K 线、美国线和折线,实时流式更新。



订单流
20 个示例 →足迹图、深度热力图和市场轮廓,走计算着色器路径。



加密衍生品
15 个示例 →资金费率、持仓量、清算和基差,显示在价格下方的窗格中。



期权与波动率
18 个示例 →隐含波动率与已实现波动率、偏斜、预期波动幅度和做市商敞口随时间的变化。



组合、风险与量化
24 个示例 →净值曲线、回撤、滚动统计、因子研究和风险检查。



自定义系列与插件
11 个示例 →堆叠、分组、箱线和刷选系列:在同一 GPU 帧上叠加图层插件。
浏览全部 20 个应用场景
价格走势
K 线类型与变换
技术分析
订单流
执行与交易复盘
加密衍生品
链上数据
DeFi 与 AMM
Meme 币与钱包
股票与基本面
A 股
期权与波动率
利率、外汇与宏观
期货与大宗商品
基金与 ETF
组合、风险与量化
私募市场与个人理财
预测市场
自定义系列与插件
实验室与旗舰示例
K 线 + 成交量
1 / 25The classic view. A day of real one-minute bars, updating every second, on a GPU-rendered price scale with a volume histogram below. Drag to pan, scroll or pinch to zoom.
FerroChart.createaddCandlestickSeriesaddVolumeSeries拖动平移 · 滚轮或双指缩放 · 双击复位实时数据 · OKXcandles
特性
为行情数据而设计。
跨平台渲染
同一个 Rust 内核:浏览器中使用 WebGPU 和 WebGL2 后端,原生应用中通过 wgpu 运行在 Metal、Vulkan 和 DirectX 12 上,服务器上使用 CPU 渲染器。黄金图像测试保证各后端输出一致。
性能与数据量无关
K 线数据常驻 GPU,坐标变换在着色器中完成,平移和缩放只需更新少量 uniform。多级细节金字塔让数千万根 K 线依然流畅。
30 个内置指标
从 SMA 到一目均衡表的均线、通道和震荡指标。每个 tick 增量更新,并用参考数据测试。
29 种画线工具
趋势线、通道、斐波那契工具、叉子线、江恩角度线、形态、艾略特波浪、区间、仓位和文字,支持撤销与重做。画线和图表状态可序列化为 JSON。
多图联动
同步组可在多个图表之间联动十字光标和可见范围。
易于扩展
自定义系列、图层和画线工具的插件接口。提供 JavaScript、Rust 和 Python 绑定,以及供 C#、C++、Qt 和 Flutter 使用的 C ABI。
开始使用
每种语言,同一套 API。
所有绑定遵循同一模型:创建图表、添加系列、设置数据、添加指标。数据按列传入,可以是类型化数组、Rust 切片或 DataFrame。
- JavaScript 与 TypeScript
- Rust
- Python 与 Jupyter
- C、C#、C++
import { FerroChart } from '@ferrochart/core';
const chart = await FerroChart.create(canvas, { theme: 'dark' });
const candles = chart.addCandlestickSeries();
chart.addVolumeSeries(candles);
candles.setData(bars); // [{ time, open, high, low, close, volume }, ...]
chart.addIndicator(candles, 'ema', { n: 20 });
chart.addIndicator(candles, 'macd'); // in a new pane