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

Core Concepts

Previous
Quick Start
Next
Chart Grammar

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...

To better use F2 for data visualization, we need to understand the composition of F2 charts and related terminology.

Chart Structure

F2 charts adopt a declarative component-based architecture. A complete chart is composed of multiple components:

Canvas (Canvas Container)
└── Chart (Chart Core)
├── Axis (Coordinate Axis)
├── Geometry (Geometry Mark)
├── Tooltip (Tooltip)
├── Legend (Legend)
└── Guide (Guide Mark)

Chart Examples

Core Terminology

TermEnglishDescription
Coordinate AxisAxisCharts typically contain two axes. In Cartesian coordinates, these are the x-axis and y-axis; in polar coordinates, they are composed of angle and radius. Each axis consists of axis line, tick line, label, and grid.
LegendLegendAn auxiliary element for charts, used to indicate different data types and ranges, assisting in reading charts and helping users filter data.
Geometry MarkGeometryGeometric shapes such as points, lines, and areas. The type of geometry mark determines the chart type and represents the actual visualization of data.
Graphic AttributeAttributeCorresponds to visual channels in visual encoding, including position, color, size, and shape.
Coordinate SystemCoordinateA 2D positioning system combining two position scales, describing how data is mapped to the graphic plane.
TooltipTooltipDisplays data information in a tooltip when hovering over a point, helping users obtain specific data.
Guide MarkGuideUseful for drawing auxiliary lines, boxes, or text on charts, such as warning lines, maximum value lines, or highlighting specific ranges.

Declarative Syntax

F2 uses declarative JSX syntax for more intuitive and concise code:

<Canvas context={context} pixelRatio={window.devicePixelRatio}>
<Chart data={data}>
{/* Coordinate axes */}
<Axis field="genre" />
<Axis field="sold" />
{/* Geometry mark - bar chart */}
<Interval x="genre" y="sold" color="genre" />
{/* Tooltip */}
<Tooltip />
{/* Legend */}
<Legend />
</Chart>
</Canvas>

Advantages of Declarative Syntax

  • Intuitive: Clear component structure at a glance
  • Concise: Avoid complex API call chains
  • Composable: Components can be combined and nested flexibly
  • Framework-friendly: Seamless integration with React, Vue

Component Details

Canvas - Canvas Container

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

<Canvas context={context} pixelRatio={window.devicePixelRatio}>
{/* Child components */}
</Canvas>
PropTypeDefaultDescription
contextCanvasRenderingContext2D-Required, Canvas 2D context
pixelRationumberwindow.devicePixelRatioDevice pixel ratio
widthnumber-Canvas width
heightnumber-Canvas height
animatebooleantrueWhether to enable animation

Chart - Chart Core

Chart is responsible for data processing and coordinate transformation:

<Chart data={data}>
{/* Geometry marks and components */}
</Chart>
PropTypeDefaultDescription
dataData[]-Required, data source
scaleScaleConfig-Scale configuration
coordCoordConfig-Coordinate system configuration

Geometry - Geometry Mark

Geometry marks determine the chart type. F2 provides various built-in geometry marks:

Geometry MarkComponentChart Type
Interval<Interval />Bar chart, column chart
Line<Line />Line chart, curve chart
Point<Point />Scatter plot, dot plot
Area<Area />Area chart
Candlestick<Candlestick />Candlestick chart
// Bar chart
<Interval x="genre" y="sold" color="genre" />
// Line chart
<Line x="date" y="value" color="type" />
// Scatter plot
<Point x="weight" y="height" color="gender" />

Graphic Attributes

Graphic attributes control the visual appearance of geometry marks:

AttributeDescriptionExample
positionPosition, maps fields to x or y axisx="genre", y="sold"
colorColor, supports field or functioncolor="genre" or color={datum => datum.value > 100 ? 'red' : 'blue'}
sizeSize, controls point size, line thickness, etc.size={10} or size={datum => datum.value}
shapeShape, controls the shape of geometry marksshape="circle" or shape="hollowCircle"

Coordinate System

Coordinate system describes how data is mapped to the plane:

TypeDescriptionConfiguration
rectCartesian coordinate system (default)<coord type="rect" />
polarPolar coordinate system<coord type="polar" />
helixHelix coordinate system<coord type="helix" />
// Use polar coordinate system (pie chart, rose chart, etc.)
<Chart data={data} coord={{ type: 'polar' }}>
<Interval x="genre" y="sold" color="genre" coord="polar" />
</Chart>

Scale

Scale is used to convert data into graphic attributes:

<Chart
data={data}
scale={{
sold: {
min: 0,
max: 500,
tickCount: 5,
},
genre: {
type: 'cat',
},
}}
>
{/* ... */}
</Chart>

For detailed configuration, see: Scale

Data Format

F2 requires the data source to be a JSON array, where each element is a standard JSON object:

const data = [
{ genre: 'Sports', sold: 275, year: 2023 },
{ genre: 'Strategy', sold: 115, year: 2023 },
{ genre: 'Action', sold: 120, year: 2023 },
{ genre: 'Shooter', sold: 350, year: 2023 },
{ genre: 'Other', sold: 150, year: 2023 },
];

For data processing, see: Data Processing

Complete Example

const data = [
{ genre: 'Sports', sold: 275 },
{ genre: 'Strategy', sold: 115 },
{ genre: 'Action', sold: 120 },
{ genre: 'Shooter', sold: 350 },
{ genre: 'Other', sold: 150 },
];
const context = document.getElementById('container').getContext('2d');
const { props } = (
<Canvas context={context} pixelRatio={window.devicePixelRatio}>
<Chart
data={data}
scale={{
sold: {
min: 0,
tickInterval: 50,
},
}}
>
<Axis field="genre" />
<Axis field="sold" />
<Interval x="genre" y="sold" color="genre" />
<Tooltip />
<Legend />
</Chart>
</Canvas>
);
const canvas = new Canvas(props);
canvas.render();

Next Steps

  • Learn Chart Grammar
  • Understand Data Processing
  • View Component API
  • Learn Graphic Attributes