开源图表引擎
Meme 真实性图层
把数据源显示的内容和真实成交区分开。索引器在没有兑换的分钟里补出的 K 线画成空心;页面当作错误报价截断的影线两端各有一道短横,悬停时提示框显示原始报价(setBarFlags)。16 个追踪钱包的最大 300 笔成交显示为头像,并跨 K 线聚合(markerCluster)。点击“+k”徽标会放大到它覆盖的 K 线;点击头像会用事件返回的标记对象打开该钱包的卡片。你自己的成交画在实际成交价上(atPrice)。所有数据均为模拟数据。
Meme 真实性图层:Meme 币与钱包示例
setBarFlags · markerCluster · position: 'atPrice' · chart.on('click') · markerHover
代码
import { FerroChart } from '@ferrochart/core';
const canvas = document.querySelector('canvas');
// Market data: the synthetic FerroChart demo API. Use your own feed.
const chart = await FerroChart.create(canvas, { theme: 'dark' });
const to = Math.floor(Date.now() / 60_000) * 60_000; // the last whole minute
const from = to - 120 * 60_000;
const range = 'symbol=MEME&from=' + from + '&to=' + to;
const bars = await fetch('/api/bars?interval=1m&' + range).then((r) => r.json());
const trades = await fetch('/api/trades?' + range).then((r) => r.json());
const n = bars.time.length;
// A feed is not the market (synthetic here): the indexer fills quiet minutes
// with flat bars, and a few bad prints leave absurd wicks.
const quiet = [...bars.volume].sort((a, b) => a - b)[Math.floor(n * 0.06)];
const filled = bars.time.map((_, i) => i > 0 && bars.volume[i] <= quiet);
filled.forEach((f, i) => { if (f) bars.open[i] = bars.high[i] = bars.low[i] = bars.close[i] = bars.close[i - 1]; });
[n - 96, n - 58, n - 21].forEach((i, k) => { filled[i] = false; if (k === 1) bars.low[i] *= 0.45; else bars.high[i] *= 1.8; });
// Clip wicks longer than 3 median ranges past the body; keep the raw prints.
const cap = 3 * bars.high.map((h, i) => h - bars.low[i]).sort((a, b) => a - b)[n >> 1];
const raw = new Map(); // bar index -> [high, low] as printed
for (let i = 0; i < n; i++) {
const top = Math.max(bars.open[i], bars.close[i]) + cap, bottom = Math.min(bars.open[i], bars.close[i]) - cap;
if (bars.high[i] <= top && bars.low[i] >= bottom) continue;
raw.set(i, [bars.high[i], bars.low[i]]);
bars.high[i] = Math.min(bars.high[i], top);
bars.low[i] = Math.max(bars.low[i], bottom);
}
const candles = chart.addCandlestickSeries({ markerCluster: 36 }); // one avatar and "+k" per 36 px
candles.setData(bars);
candles.setBarFlags(bars.time.flatMap((time, i) => (filled[i] || raw.has(i) ? [{ time, filled: filled[i], clipped: raw.has(i) }] : [])));
// 16 tracked wallets (synthetic) and the 300 largest trades, attributed to them.
const wallets = ['moonboy', 'gm_capital', 'ape_lord', 'sigma.sol', 'wenlambo', 'quiet_whale', 'degen_daily', 'early_bird',
'chart_wizard', 'delta_fund', 'pump_watch', 'cold_wallet', 'meme_queen', 'alpha_desk', 'ngmi_labs', 'flow_reader']
.map((name, i) => ({ name, kind: i % 2 ? 'Smart' : 'KOL', icon: 'w' + (i + 1), buys: 0, sells: 0, n: 0 }));
await Promise.all(wallets.map((w, i) => chart.registerIcon(w.icon, '/avatars/w' + String(i + 1).padStart(2, '0') + '.png')));
const fills = trades.time
.map((time, i) => ({ time, price: trades.price[i], usd: trades.price[i] * trades.size[i], buy: trades.side[i] > 0, wallet: wallets[(i * 7 + 3) % 16] }))
.sort((a, b) => b.usd - a.usd)
.slice(0, 300);
fills.forEach((f) => { f.wallet.n++; f.wallet[f.buy ? 'buys' : 'sells'] += f.usd; });
// Each marker carries its fill: events hand back the very object.
const markers = fills.map((fill, i) => ({
id: i + 1, fill, time: fill.time, position: fill.buy ? 'belowBar' : 'aboveBar', icon: fill.wallet.icon, size: 18,
color: '#1b1f2a', border: fill.buy ? '#2ee6b6' : '#ff5d73', borderWidth: fill.wallet.kind === 'Smart' ? 3 : 1.5,
}));
// Your own fills, at the price they executed (never clustered).
[0.2, 0.45, 0.7, 0.9].forEach((q, k) => {
const i = Math.floor(q * trades.time.length), buy = k % 2 === 0;
markers.push({ id: 1000 + k, mine: true, time: trades.time[i], position: 'atPrice', price: trades.price[i], shape: 'square',
label: 'ME', size: 16, color: buy ? '#2ee6b6' : '#ff5d73', text: (buy ? 'buy ' : 'sell ') + trades.price[i].toPrecision(4) });
});
candles.setMarkers(markers.sort((a, b) => a.time - b.time));
// Tooltips (hovered marker or flagged bar) and a wallet card (clicked avatar).
const usd = (v) => (v >= 1e6 ? '$' + (v / 1e6).toFixed(1) + 'M' : '$' + (v / 1e3).toFixed(0) + 'k');
let mark = null, bar = null, card = null; // tooltips of a marker and a flagged bar, a wallet card
const box = (ctx, x, y, rows) => {
const width = 16 + Math.max(...rows.map((r) => ctx.textWidth(r, 11)));
const height = 10 + rows.length * 16; // kept inside the plot
x = Math.max(ctx.rect.x, Math.min(x, ctx.rect.x + ctx.rect.width - width));
y = Math.max(ctx.rect.y, Math.min(y, ctx.rect.y + ctx.rect.height - height));
return [{ type: 'rect', x, y, width, height, color: 'rgba(17, 20, 28, 0.92)' },
...rows.map((text, i) => ({ type: 'text', x: x + 8, y: y + 5 + i * 16, text, size: 11, color: i ? '#e6ebf5' : '#8a93a6' }))];
};
const layer = chart.addLayer({ pane: 0, position: 'overlay', build: (ctx) => {
const tip = mark ?? bar;
return [...(card ? box(ctx, ctx.rect.x + 10, ctx.rect.y + 10, card) : []),
...(tip ? box(ctx, tip.x + 14, tip.y - 20, tip.rows) : [])];
} });
chart.on('markerHover', (e) => {
const f = e?.marker.fill;
mark = !e ? null : { x: e.x, y: e.y, rows:
e.overflow ? [e.overflow + ' more trades', 'over ' + (e.bars.to - e.bars.from + 1) + ' min, click to zoom']
: e.marker.mine ? ['your fill', e.marker.text]
: [f.wallet.name + ' (' + f.wallet.kind + ')', (f.buy ? 'buy ' : 'sell ') + usd(f.usd) + ' at ' + f.price.toPrecision(4)] };
chart.invalidateLayer(layer);
});
chart.on('crosshairMove', ({ point }) => {
const i = point ? Math.round(point.logicalIndex) : -1, w = raw.get(i);
const next = w ? ['wick clipped', 'printed high ' + w[0].toPrecision(4) + ', low ' + w[1].toPrecision(4)]
: filled[i] ? ['filled bar', 'no swaps this minute'] : null;
if (next || bar) { bar = next && { x: point.x, y: point.y, rows: next }; chart.invalidateLayer(layer); }
});
chart.on('click', (e) => {
const t = e.target;
if (t?.type === 'markerOverflow') return chart.setVisibleLogicalRange(t.bars.from - 10, t.bars.to + 10);
const w = t?.type === 'marker' && t.marker.fill?.wallet;
card = w ? [w.name + ' (' + w.kind + ')', w.n + ' trades in 2h', 'bought ' + usd(w.buys) + ', sold ' + usd(w.sells), 'net ' + (w.buys >= w.sells ? '+' : '-') + usd(Math.abs(w.buys - w.sells))] : null;
chart.invalidateLayer(layer);
});
chart.setBarSpacing(8);
chart.scrollToRealtime();为逐笔级数据而生。
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