logo

F2

  • Manual
  • Component Documentation
  • Examples
  • Productsantv logo arrow
  • 5.10.0
  • Quick Start
  • Core Concepts
  • Chart Grammar
  • Data Processing
  • Scale
  • Coordinate System
  • Framework
    • 小程序上渲染 F2
  • Advanced
  • Question

Quick Start

Next
Core Concepts

Resource

Ant Design
Galacea Effects
Umi-React Application Framework
Dumi-Component doc generator
ahooks-React Hooks Library
WeaveFox-AI Coding Assistant

Community

Ant Financial Experience Tech
seeconfSEE Conf-Experience Tech Conference
weavefoxWeaveFox-AI Developer Community

Help

GitHub
StackOverflow

more productsMore Productions

Ant DesignAnt Design-Enterprise UI design language
yuqueYuque-Knowledge creation and Sharing tool
EggEgg-Enterprise-class Node development framework
kitchenKitchen-Sketch Tool set
GalaceanGalacean-Interactive solution
weavefoxWeaveFox-AI Coding Assistant
© Copyright 2026 Ant Group Co., Ltd..备案号:京ICP备15032932号-38

Loading...

This guide will help you get started with F2, from installation to rendering your first chart.

Features

Starting from F2 4.0, we use declarative programming to build charts, providing a more intuitive development experience:

Declarative

Declarative programming makes code more intuitive and concise, avoiding complex API calls. F2 uses JSX syntax, which is not only easy to use but also integrates seamlessly with frameworks like React and Vue.

Component-Based

Components are essential for building complex visualizations. F2 follows React's design patterns and provides a complete set of component capabilities, making it simple to encapsulate your own components.

Installation

Install via npm

npm install @antv/f2 --save

Install via CDN

<script src="https://unpkg.com/@antv/f2/dist/index.min.js"></script>

Configure JSX Transform

F2 uses JSX syntax to build charts, so you need to configure JSX transformation tools.

Note: If your project is already using React, refer to How to use with React

For detailed configuration instructions, see: Configure JSX Transform

One-Minute Quick Start

1. Create a canvas element

Create a <canvas> element on your page:

<canvas id="myChart" width="400" height="260"></canvas>

2. Write the code

// F2 requires data in JSON array format, where each element is a standard JSON object
const data = [
{ genre: 'Sports', sold: 275 },
{ genre: 'Strategy', sold: 115 },
{ genre: 'Action', sold: 120 },
{ genre: 'Shooter', sold: 350 },
{ genre: 'Other', sold: 150 },
];
// Get canvas context
const context = document.getElementById('myChart').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();

After completing these two steps, save the file and open it in your browser. A bar chart will be successfully rendered:

Code Analysis

Canvas Component

Canvas is the root container of the chart, responsible for providing the rendering environment:

PropTypeDefaultDescription
contextCanvasRenderingContext2D-Required, Canvas 2D context
pixelRationumberwindow.devicePixelRatioDevice pixel ratio for high-DPI screen adaptation
widthnumber-Canvas width (prioritizes canvas element's width)
heightnumber-Canvas height (prioritizes canvas element's height)
animatebooleantrueWhether to enable animation
childrenReactNode-Child components

Chart Component

Chart is the core component of the chart, responsible for data processing and coordinate transformation:

PropTypeDefaultDescription
dataData[]-Required, data source
scaleScaleConfig-Scale configuration
coordCoordConfig-Coordinate system configuration
childrenReactNode-Child components

Interval Component

Interval is used to render bar charts:

PropTypeDefaultDescription
xstring-Required, x-axis field name
ystring-Required, y-axis field name
colorstring | Function-Color field or color mapping function

Axis Component

Axis is used to configure coordinate axes:

PropTypeDefaultDescription
fieldstring-Required, field name
positionstring-Axis position (top, bottom, left, right)

Tooltip Component

Tooltip is used to display data tooltip information.

More Examples

For more examples, see Demos.

Next Steps

  • Learn about Core Concepts
  • Study Chart Grammar
  • View Component API
  • Learn how to Use with Frameworks