logo

Ant Design Charts

  • Manual
  • Options
  • Examples
  • Productsantv logo arrow
  • 2.0.0
  • Component Overview
  • Common Configuration Statistical Charts
    • Chart composition
    • Component
      • 标题(Title)
      • Axis
      • Legend
      • Scrollbar
      • Slider
      • Tooltip
      • Label
    • Core
      • Color En
      • View
      • Data
        • overview
        • custom
        • ema
        • fetch
        • filter
        • fold
        • inline
        • join
        • kde
        • log
        • map
        • pick
        • rename
        • slice
        • sort
        • sortBy
      • Scale
        • overview
        • band
        • linear
        • log
        • ordinal
        • point
        • pow
        • quantile
        • quantize
        • sqrt
        • threshold
        • time
      • Transform
        • overview
        • bin
        • binX
        • diffY
        • dodgeX
        • flexX
        • group
        • groupColor
        • groupX
        • groupY
        • jitter
        • jitterX
        • jitterY
        • normalizeY
        • pack
        • sample
        • select
        • selectX
        • selectX
        • sortColor
        • sortX
        • sortY
        • stackEnter
        • stackY
        • symmetryY
      • Coordinate
        • overview
        • fisheye
        • parallel
        • polar
        • radial
        • theta
        • transpose
        • cartesian3D
      • 样式(Style)
      • Animate
        • overview
        • fadeIn
        • fadeOut
        • growInX
        • growInY
        • morphing
        • pathIn
        • scaleInX
        • scaleInY
        • scaleOutX
        • scaleOutY
        • waveIn
        • zoomIn
        • zoomOut
      • 状态(State)
      • Interaction
        • Overview
        • brushAxisHighlight
        • brushHighlight
        • brushXHighlight
        • brushYHighlight
        • brushFilter
        • brushXFilter
        • brushYFilter
        • chartIndex
        • elementHighlight
        • elementHighlightByColor
        • elementHighlightByX
        • elementSelect
        • elementSelectByColor
        • elementSelectByX
        • fisheye
        • legendFilter
        • legendHighlight
        • poptip
        • scrollbarFilter
        • sliderFilter
      • Composition
        • overview
        • facetCircle
        • facetRect
        • repeatMatrix
        • spaceFlex
        • spaceLayer
        • timingKeyframe
      • Theme
        • overview
        • Academy
        • classic
        • classicDark
      • event
    • Specal Plot
      • Area
      • Bar
      • CirclePacking
      • DualAxes
      • Gauge
      • Line
      • Rose
      • Sankey
      • Scatter
      • Sunburst
      • Treemap
      • Venn
      • WordCloud
      • Column
      • Pie
      • BidirectionalBar
      • Box
      • Bullet
      • Funnel
      • Heatmap
      • Histogram
      • Liquid
      • Radar
      • Stock
      • Tiny
      • Violin
      • Waterfall
      • RadialBar
  • Relation Graph Components
    • Overview
    • MindMap
    • Fishbone
    • IndentedTree
    • Dendrogram
    • OrganizationChart
    • FlowGraph
    • FlowDirectionGraph
    • NetworkGraph
    • FAQ

shape

Next
Component Overview

Resources

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

Community

Ant Financial Experience Tech
seeconfSEE Conf-Experience Tech Conference

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-互动图形解决方案
xtechLiven Experience technology
© Copyright 2025 Ant Group Co., Ltd..备案号:京ICP备15032932号-38

Loading...

通常用来在图表上绘制一个静态的自定义图形,灵活性非常高,当然技术成本也会高一些,需要了解 G 的 API 去绘制图形。

开始使用

shape

上图中的「数据保密」的徽章图案就是使用 shape 绘制。在绘制图形时,可以从图表上下文中获取 document 对象,随后使用 document.createElement 创建基础图形。在下面的示例中我们创建了一个 Circle。

{
annotations: [
{
type: 'shape',
style: {
x: '80%',
y: '70%',
render: ({ x, y }, context, d) => {
const { document } = context;
const g = document.createElement('g', {});
const c1 = document.createElement('circle', {
style: {
cx: x,
cy: y,
lineWidth: 4,
r: 65,
stroke: 'red',
opacity: 0.3,
},
});
const c2 = document.createElement('circle', {
style: {
cx: x,
cy: y,
lineWidth: 2,
r: 50,
stroke: 'red',
opacity: 0.3,
},
});
const text = document.createElement('text', {
style: {
x,
y,
text: '数据保密',
transform: 'rotate(30)',
fontSize: 20,
fill: 'red',
textAlign: 'center',
textBaseline: 'middle',
fillOpacity: 0.3,
},
});
g.appendChild(c1);
g.appendChild(c2);
g.appendChild(text);
return g;
},
},
},
],
};

可以查看图表徽章水印具体示例。

选项

属性描述类型默认值-
x设置图形的位置 x,支持百分比('50%')和像素值(200)numberstring-
y设置图形的位置 y,支持百分比('50%')和像素值(200)numberstring-
render对应的自定义渲染函数,函数需要返回 G 的 DisplayObject(style: object) => DisplayObject-
{ ...rest }自定义图形的额外参数,都会作为 render 函数的第一个参数属性object-