AgentSkillsCN

antv-f2

适用于使用 AntV F2 构建移动端优先的可视化图表,包括折线图、柱状图、饼图、面积图、散点图、雷达图、蜡烛图、仪表盘图、树状图或太阳花图。

SKILL.md
--- frontmatter
name: antv-f2
description: Use when building mobile-first visualization charts with AntV F2, creating JSX-based charts including line, bar, pie, area, scatter, radar, candlestick, gauge, treemap, or sunburst charts

AntV F2 Charting Library

Overview

AntV F2 is a mobile-first, high-performance charting library based on the Grammar of Graphics. It uses JSX syntax for declarative chart creation.

When to Use

  • Building mobile visualization charts
  • Creating interactive charts with touch gestures
  • Implementing charts in React, Vue, or mini-programs
  • Need lightweight canvas-based charting

Quick Reference

Core Components

ComponentPurposeExample
CanvasRoot container<Canvas context={ctx}>
ChartData/scale/coord config<Chart data={data}>
LineLine/curve charts<Line x="date" y="value" />
IntervalBar/pie/donut charts<Interval x="cat" y="val" />
PointScatter/bubble charts<Point x="x" y="y" size="val" />
AreaArea charts<Area x="date" y="value" />
CandlestickK-line charts<Candlestick x="date" y="ohlc" />
AxisAxis configuration<Axis field="date" />
TooltipHover/press tooltip<Tooltip showCrosshairs />
LegendSeries legend<Legend position="top" />
ScrollBarPan/zoom control<ScrollBar mode="x" range={[0.5,1]} />

Standalone Charts

ComponentPurpose
GaugeProgress/meter display
TreemapHierarchical rectangles
SunburstHierarchical radial chart

Chart Types Quick Mapping

Chart TypeComponentsKey Props
Line chartLinex, y, color
Column chartIntervalx, y
Bar chartIntervalcoord={{ transposed: true }}
Pie chartIntervalcoord={{ type: 'polar', transposed: true }}, adjust="stack"
Donut chartSame as pieAdd innerRadius: 0.6 to coord
Radar chartLine + Pointcoord="polar"
Area chartArea + Linex, y
Scatter plotPointx, y, color, size
Stacked barIntervaladjust="stack"
Grouped barIntervaladjust="dodge"

Basic Structure

jsx
import { jsx, Canvas, Chart, Line, Axis, Tooltip } from '@antv/f2';

const data = [
  { date: '2023-01', value: 100 },
  { date: '2023-02', value: 150 },
];

const context = document.getElementById('container').getContext('2d');

const { props } = (
  <Canvas context={context} pixelRatio={window.devicePixelRatio}>
    <Chart data={data}>
      <Axis field="date" />
      <Axis field="value" />
      <Line x="date" y="value" />
      <Tooltip />
    </Chart>
  </Canvas>
);

const chart = new Canvas(props);
chart.render();

Common Patterns

Color Mapping

jsx
<Line color="#1890FF" />           // Fixed color
<Line color="category" />          // Field mapping
<Line color={["type", ["red", "blue"]]} />  // Custom range
<Line color={{ field: "val", callback: v => v > 50 ? "red" : "blue" }} />

Coordinate Systems

jsx
// Cartesian (default)
<Chart coord={{ type: 'rect', transposed: false }}>

// Polar (pie/radar)
<Chart coord={{ type: 'polar', transposed: true, innerRadius: 0.5 }}>

Data Adjustment

jsx
<Interval adjust="stack" />   // Stacked
<Interval adjust="dodge" />   // Grouped

Scale Configuration

jsx
<Chart
  scale={{
    value: { min: 0, max: 100, tickCount: 5, formatter: v => v + '%' },
    date: { type: 'timeCat', mask: 'YYYY-MM-DD' },
  }}
>

References

TopicReference
Full API Documentation@reference.md
Line charts@references/line.md
Area charts@references/area.md
Column charts@references/column.md
Bar charts (horizontal)@references/bar.md
Pie/Donut charts@references/pie.md
Scatter/Bubble charts@references/point.md
Radar charts@references/radar.md
Funnel charts@references/funnel.md
Candlestick (K-line)@references/candlestick.md
Treemap/Sunburst@references/relation.md
Axis/Guide/Legend@references/component.md

Common Mistakes

MistakeFix
Blurry on mobileSet pixelRatio={window.devicePixelRatio}
Pie chart not circularUse coord={{ type: 'polar', transposed: true }}
Missing legendAdd <Legend /> and use color prop on geometry
ScrollBar not workingBoth mode and range are required
Animation too fast/slowConfigure animation={{ appear: { duration: 800 } }}
Axis labels overlappingUse labelAutoRotate={true} or labelAutoHide={true}