F2 is a mobile-first JavaScript charting library from Ant Group's AntV family, built for developers who need elegant, interactive data visualisation across H5, mini-program, Node.js, React Native, and Weex from a single codebase.
What it is
F2 is an open-source charting library focused on mobile rendering, distributed through AntV, the visualisation ecosystem maintained by Ant Group. It is written in JavaScript, licensed under MIT, and published to npm as @antv/f2. Its design rests on the Grammar of Graphics theory proposed by Leland Wilkinson, which the project credits as the foundation for its compositional approach to building charts.
The concrete problem F2 solves is the mismatch between desktop-oriented chart libraries and the constraints of mobile devices. Traditional libraries wrap each chart type in its own dedicated component, which bloats bundles and limits flexibility on small screens. F2 abandons that per-chart encapsulation in favour of data-driven composition, where charts are assembled from grammar primitives. This keeps the bundle small — 44k gzipped without interactions, 56k with all interaction code — while still covering more than 50 chart types, and it lets the same code render across H5, mini-program, Node.js, React Native, and Weex environments.
Key capabilities
- Renders over 50 chart types by composing Grammar of Graphics primitives instead of per-chart wrappers.
- Keeps bundle size to 44k gzipped without interactions and 56k with all interactions included.
- Supports modular design and dynamic loading to further reduce shipped size.
- Renders in multiple environments from one codebase: H5, Node.js, Alipay mini-program, WeChat mini-program via
wx-f2, React Native via f2-demo, and Weex.
- Accepts a JSON array of standard JSON objects as its data source, with no schema beyond plain objects.
- Exposes extensible Shape, animation, and interaction mechanisms for custom chart behaviour and styling.
- Uses HTML5 canvas for rendering, as reflected in the project's
html5-canvas topic.
Who uses it and how
- Mobile H5 teams that need interactive charts optimised for fragmented user attention on small screens.
- Mini-program developers targeting Alipay or WeChat, where F2 renders through the same grammar API.
- Cross-platform teams using React Native or Weex that want one chart codebase for native and web targets.
- Server-side or Node.js pipelines rendering charts outside a browser context.
- Performance-conscious teams that use modular dynamic loading to ship only the chart and interaction code in use.
Getting started
Install with npm install @antv/f2, then build a chart from a JSON array via a canvas context and the Canvas component, as shown in the quick-start example.
How it compares
No comparable projects or paid alternatives are named in the registry facts for this listing, so F2 stands alone in this registry without a stated replacement set.
When to use it — and when not to
F2 suits mobile and multi-environment charting where bundle size and interaction quality matter more than exhaustive desktop-dashboard features. It carries 303 open issues, and its primary documentation is in Chinese with a separate English README, which raises friction for teams that do not read Chinese. Teams building large desktop-first analytics dashboards, or those needing heavy server-side data aggregation, should weigh whether a fuller-featured charting stack fits better.
project readme (upstream, from github) — read inline


F2,一个专注于移动,开箱即用的可视化解决方案,完美支持 H5 环境同时兼容多种环境(node, 小程序,weex)。完备的图形语法理论,满足你的各种可视化需求。专业的移动设计指引为你带来最佳的移动端图表体验。英文 README

在此衷心感谢《The Grammar of Graphics》的作者 Leland Wilkinson,为 F2 的图形语法提供了理论基础!
安装
$ npm install @antv/f2
特性
专注移动,体验优雅
- 轻量化呈现,自然反馈:在设计上我们以人为本,追求自然简单易懂,有吸引力的表达效果,让用户在碎片化的时间里更快更高效得获取图表信息。同时在可视化的操作我们追求内容和操作有机融合,符合人的自然行为反应,让交互操作更自然。


轻巧流畅:F2 一直致力于追求极致的性能,针对移动设备做了大量的优化,在支持丰富(50+)图表的基础上同时保持代码量的小巧(不带交互版本 gzip 压缩后 44k,带所有交互版本 56k),同时提供模块化的设计以支持动态加载,提供更优的大小。
多端异构:在完美支持 H5 环境的同时,同时兼容 Node.js,支付宝小程序、微信小程序、React Native以及 Weex 端的渲染,一份代码,多设备多环境渲染。

图表丰富,组件完备
与传统的图表库不同,抛弃了特图特做的封装思路,基于强大的图形语法理论,以数据驱动,通过图形语法的组合灵活构建各类图表,目前可绘制 50+ 图表类型(当然,还可以更多),覆盖各类场景在提供基础的图表可视化能力外,我们还提供了丰富图表功能组件,满足各种功能需求。

扩展灵活,创意无限
我们在提供最佳实践的同时,还为开发者提供了灵活的扩展机制,包括 Shape、动画以及交互的自定义能力,当然还有图表样式的个性化定制,满足各种个性化的图表要求。




文档
快速开始

<canvas id="mountNode"></canvas>
// F2 对数据源格式的要求,仅仅是 JSON 数组,数组的每个元素是一个标准 JSON 对象。
const data = [
{ genre: 'Sports', sold: 275 },
{ genre: 'Strategy', sold: 115 },
{ genre: 'Action', sold: 120 },
{ genre: 'Shooter', sold: 350 },
{ genre: 'Other', sold: 150 },
];
// 获取 canvas context
const context = document.getElementById('mountNode').getContext('2d');
const { props } = (
<Canvas context={context} pixelRatio={window.devicePixelRatio}>
<Chart data={data}>
<Axis field="genre" />
<Axis field="sold" />
<Interval x="genre" y="sold" color="genre" />
<Tooltip />
</Chart>
</Canvas>
);
const canvas = new Canvas(props);
canvas.render();
更多示例:demos。
手机扫码观看 demos

本地开发
$ npm install
# 先初始化 monorepo
$ npm run bootstrap
# 再跑测试用例
$ npm run test
# 监听文件变化构建,并打开 demo 页面
$ npm run dev
# 打开某一个具体的测试用例
$ npm run test-watch -- 'TestFileName'
如何贡献
如果您在使用的过程中碰到问题,可以先通过 issues 看看有没有类似的 bug 或者建议。
如需提交代码,请遵从我们的贡献指南。
体验改进计划说明
F2 从 3.1.12(2018-06-20 发布)版本开始添加了F2.track(true)方法。 目前我们的体验改进计划已经完成,所以从 3.3.4 版本开始该方法将从 F2 中删除。 如果它给你带来麻烦,我们深表歉意。
License
MIT license.