logo

F2

  • 教程
  • 组件API
  • 图表示例
  • 所有产品antv logo arrow
  • 5.0.3
  • 快速上手
  • 图表组成
  • 图形语法
  • 数据 - Data
  • 度量 - Scale
  • 坐标系 - Coordinate
  • 图形标签 - Shape
  • 绘图属性 - Style
  • 动画属性 - Animation
  • 事件属性 - Event
  • 图形使用 - JSX
  • 组件介绍 - Component
  • 多端/框架 - Framework
    • 多端适配
    • 如何在 React 中使用
    • 如何在 Vue 中使用
    • 如何在小程序中使用
    • 如何在 Node.js 中使用
    • 配置 jsx transform
    • 使用 svg 渲染
  • 进阶 - Advanced
    • 自定义 View
  • 常见问题 - Question
    • 和 React 同时使用时,TS 类型报错

图形标签 - Shape

上一篇
坐标系 - Coordinate
下一篇
绘图属性 - Style

Resources

Ant Design
Galacea Effects
Umi-React 应用开发框架
Dumi-组件/文档研发工具
ahooks-React Hooks 库

社区

体验科技专栏
seeconfSEE Conf-蚂蚁体验科技大会

帮助

GitHub
StackOverflow

more products更多产品

Ant DesignAnt Design-企业级 UI 设计语言
yuque语雀-知识创作与分享工具
EggEgg-企业级 Node 开发框架
kitchenKitchen-Sketch 工具集
GalaceanGalacean-互动图形解决方案
xtech蚂蚁体验科技
© Copyright 2025 Ant Group Co., Ltd..备案号:京ICP备15032932号-38

Loading...

F2 底层使用了 G 绘图引擎。本篇列出了常见的图形标签

如何使用

详见:图形使用

图形标签

  • group 分组
    • rect 矩形
    • circle 圆
    • sector 扇形
    • polygon 多边形
    • line 线
    • arc 圆弧
    • polyline 多点线段
    • text 文本
    • image 图片

图形属性

Props

属性名类型描述
classNameString对象标记,由用户指定
visibleBoolean显示还是隐藏。
zIndexNumberz-index 值,用于调整绘制顺序。
styleStyle图形样式
animationAnimation图形动画
onPan 等Event图形事件

Style 绘图属性

更多详情可见:绘图属性

Animation 图形动画属性

更多详情可见:图形动画属性

Event 图形事件属性

更多详情可见:图形事件属性

演示

  • 图形标签

group

包含一组图形

示例

<group className="group">
<rect ... />
<rect ... />
</group>

rect

矩形

Style

属性名类型描述
xNumber左上角 x 坐标
yNumber左上角 y 坐标
widthNumber宽度
heightNumber高度
radiusNumber | Number[]圆角

示例

<rect
style={{ x: 100, y: 100, width: 50, height: 50, lineWidth: '2px', stroke: '#000', fill: 'red' }}
/>

circle

圆形

Style

属性名类型描述
cxNumber圆心 cx 坐标
cyNumber圆心 cy 坐标
rNumber圆的半径

示例

<circle style={{ cx: 100, cy: 100, r: 50, lineWidth: '2px', stroke: '#000', fill: 'red' }} />

sector

扇形

Style

属性名类型描述
cxNumber圆心 cx 坐标
cyNumber圆心 cy 坐标
rNumber外半径
r0Number内半径, 默认为 0
startAngleNumber | String起始角度/弧度, 默认 0
endAngleNumber | String结束角度/弧度,默认 0
anticlockwiseBoolean逆时针方向,默认 false

示例

<sector
style={{
cx: 100,
cy: 100,
r: 50,
startAngle: '0 rad',
endAngle: '3.14 rad',
lineWidth: '2px',
stroke: '#000',
fill: 'red',
}}
/>

polygon

多边形

Style

属性名类型描述
points[Number, Number][]多边形的点

示例

<polygon
style={{
points: [
[10, 10],
[50, 50],
[30, 70],
],
lineWidth: '2px',
stroke: '#000',
fill: 'red',
}}
/>

line

绘制直线

Style

属性名类型描述
x1Number起始点 x 坐标
y1Number起始点 y 坐标
x2Number结束点 x 坐标
y2Number结束点 y 坐标

示例

<line style={{ x1: 10, y1: 10, x2: 100, y2: 100, lineWidth: '2px', stroke: '#000' }} />

arc

绘制圆弧

Style

属性名类型描述
cxNumber圆心 cx 坐标
cyNumber圆心 cy 坐标
rNumber半径
startAngleNumber/String起始角度/弧度, 默认 0
endAngleNumber/String结束角度/弧度,默认 0
anticlockwiseBoolean逆时针方向,默认 false

示例

<arc
style={{
cx: 100,
cy: 100,
r: 50,
startAngle: 0,
endAngle: 360,
lineWidth: '2px',
stroke: '#000',
}}
/>

polyline

多点线段

Style

属性名类型描述
Points[Number, Number][]线段的点
smoothBoolean是否需要平滑,默认 false

示例

<polyline
style={{
points: [
[10, 10],
[50, 50],
[80, 70],
],
lineWidth: '2px',
stroke: '#000',
smooth: true,
}}
/>

text

文本

Style

属性名类型描述
xNumber文本位置
yNumber文本位置
textString文本内容
textAlignString设置文本内容的当前对齐方式, 支持的属性:'start', 'center', 'end', 'left', 'right'
textBaselineString设置在绘制文本时使用的当前文本基线, 支持的属性:'top', 'hanging', 'middle', 'alphabetic', 'ideographic', 'bottom'
fontStyleString规定字体样式。可能的值:'normal', 'italic', 'oblique'
fontSizeNumber规定字号,以像素计
fontFamilyString规定字体系列
fontWeightString规定字体的粗细。可能的值:'normal', 'bold', 'bolder', 'lighter', '100', '200, '300', '400','500', '600', '700', '800', '900'
fontVariantString规定字体变体。可能的值:'normal', 'small-caps'
lineHeightNumber规定行高,以像素计

示例

<text
style={{
text: '文本',
fontSize: 20,
fill: '#000',
}}
/>

image

图片

Style

属性名类型描述
xNumber左上角 x 坐标
yNumber左上角 y 坐标
widthNumber宽度
heightNumber高度
srcstring图片 url
cacheImageboolean是否需要缓存(如果图片有闪动,可以添加缓存)

示例

<image
style={{
src: 'https://f2.antv.vision/favicon-32x32.png?v=9772447a8d07a8fe19894b5176c6cb0d',
x: 10,
y: 10,
width: 32,
height: 32,
}}
/>