Skip to content
本页导航

画图数据结构

通用字段

字段名称默认值字段解释数据类型是否必填可选值备注
type图形类型string'arc' , 'circle' , 'compoundPath' , 'line' , 'polygon' , 'polyline' , 'rect' , 'text' , 'image' , 'bezierCurve' , 'sector' , 'group' , 'droplet' , 'ellipse' , 'heart' , 'isogon' , 'rose' , 'star'"bezierCurve"
stroke"none" "#fff"图形轮廓颜色string颜色值
fill"none"图形填充颜色string颜色值
fillOpacity1图形填充颜色透明度number取值范围 0-1
strokeOpacity1图形轮廓颜色透明度number取值范围 0-1
zlevel0图形层级number
draggablefalse图形是否可以拖拽boolean
params{}给图形添加的额外参数boolean对图点击等操作需要拿原数据的时候非常有用

提示

兼容未列出的 zrender.Displayable 的 其他配置 (使用时 opts 和 opts.style 平级配置)v0.1.1

如下示例

示例

json
{
  "type": "text",
  "x": 0,
  "y": 0,
  "text": "你好",
  "fontSize": 100,
  "fontWeight": 400,
  "culling": false,
  "cursor": false,
  "draggable": false,
  "progressive": -1,
  "rectHover": false,
  "silent": false,
  "fill": "#ccc",
  "stroke": "#ccc",
  "opacity": 1,
  "lineDash": null,
  "lineDashOffset": null,
  "shadowBlur": 0,
  "shadowColor": "transparent",
  ...
}

1. 直线

字段名称默认值字段解释数据类型是否必填可选值备注
type"line"图的类型string"line"
x10起始点横坐标number
y10起始点纵坐标number
x20终止点横坐标number
y20终止点纵坐标number
lineWidth1线条宽度number
lineDash"solid"线条类型string"solid"(实线) "dashed"(虚线) "dotted"(点虚线)

示例

json
{
  "type": "line",
  "x1": 0,
  "y1": 0,
  "x2": 100,
  "y2": 100,
  "stroke": "red"
}

2. 矩形

字段名称默认值字段解释数据类型是否必填可选值备注
type"rect"图的类型string"rect"
x0起始点横坐标number
y0起始点纵坐标number
width0矩形宽number
height0矩形高number

示例

json
{
  "type": "rect",
  "x": 0,
  "y": 0,
  "width": 100,
  "height": 100,
  "stroke": "red"
}

3. 闭合多边形

字段名称默认值字段解释数据类型是否必填可选值备注
type"polygon"图的类型string"polygon"
points点集合number[][]

示例

json
{
  "type": "polygon",
  "points": [
    [0, 0],
    [100, 0],
    [100, 100]
  ],
  "stroke": "red"
}

4. 不闭合多边形

字段名称默认值字段解释数据类型是否必填可选值备注
type"polyline"图的类型string"polyline"
points点集合number[][]

示例

json
{
  "type": "polyline",
  "points": [
    [0, 0],
    [100, 0],
    [100, 100]
  ],
  "stroke": "red"
}

5. 圆弧

字段名称默认值字段解释数据类型是否必填可选值备注
type"arc"图的类型string"arc"
cx0圆心横坐标number
cy0圆心纵坐标number
r0半径number
startAngle0起始角度(以水平 x 轴右方向为 0 度)number正数,负数都可以
endAngle0终止角度(以水平 x 轴右方向为 0 度)number正数,负数都可以
clockwisetrue顺时针boolean

示例

json
{
  "type": "arc",
  "cx": 0,
  "cy": 0,
  "r": 100,
  "startAngle": 0,
  "endAngle": 90
}

6. 圆

字段名称默认值字段解释数据类型是否必填可选值备注
type"circle"图的类型string"circle"
cx0圆心横坐标number
cy0圆心纵坐标number
r0半径number

示例

json
{
  "type": "circle",
  "cx": 0,
  "cy": 0,
  "r": 100
}

7. 扇形

字段名称默认值字段解释数据类型是否必填可选值备注
type"sector"图的类型string"sector"
cx0圆心横坐标number
cy0圆心纵坐标number
r0半径number
r00内半径number一般给 0
startAngle0起始角度(以水平 x 轴右方向为 0 度)number正数,负数都可以
endAngle0终止角度(以水平 x 轴右方向为 0 度)number正数,负数都可以
clockwisetrue顺时针boolean

示例

json
{
  "type": "sector",
  "cx": 0,
  "cy": 0,
  "r": 100,
  "r0": 100,
  "startAngle": 0,
  "endAngle": 90
}

8. 文本

字段名称默认值字段解释数据类型是否必填可选值备注
type"text"图的类型string"text"
x0起始点横坐标number
y0起始点纵坐标number
text文本内容string
fontSize16文本字号number
fontWeight400文本粗细number

示例

json
{
  "type": "text",
  "x": 0,
  "y": 0,
  "text": "你好",
  "fontSize": 100,
  "fontWeight": 400
}

9. 图片

字段名称默认值字段解释数据类型是否必填可选值备注
type"image"图的类型string"image"
x0起始点横坐标number
y0起始点纵坐标number
width0图片宽number
height0图片高number
image0图片string HTMLImageElement HTMLCanvasElement

示例

json
{
  "type": "image",
  "x": 0,
  "y": 0,
  "width": 100,
  "height": 100,
  "image": "./img.jpg"
}

10. 贝塞尔曲线

字段名称默认值字段解释数据类型是否必填可选值备注
type"bezierCurve"图的类型string"bezierCurve"
x10起始点横坐标number
y10起始点纵坐标number
x20终点横坐标number
y20终点纵坐标number
cpx10断点 1 横坐标number
cpy10断点 1 纵坐标number
cpx20断点 2 横坐标number
cpy20断点 2 纵坐标number

示例

json
{
  "type": "bezierCurve",
  "x1": 0,
  "y1": 0,
  "cpx1": 50,
  "cpy1": 50,
  "cpx2": 150,
  "cpy2": 150,
  "x2": 200,
  "y2": 200
}

11. 水滴

v1.0.0

字段名称默认值字段解释数据类型是否必填可选值备注
type"droplet"图的类型string"droplet"
cx0圆心横坐标number
cy0圆心纵坐标number
width0水滴宽number
height0水滴高number

示例

json
{
  "type": "droplet",
  "cx": 600,
  "cy": 600,
  "width": 168,
  "height": 168,
  "stroke": "red",
  "fill": "red"
}

12. 椭圆

v1.0.0

字段名称默认值字段解释数据类型是否必填可选值备注
type"ellipse"图的类型string"ellipse"
cx0圆心横坐标number
cy0圆心纵坐标number
rx0椭圆横向半径number
rx0椭圆纵向半径number

示例

json
{
  "type": "ellipse",
  "cx": 600,
  "cy": 600,
  "rx": 168,
  "ry": 200,
  "stroke": "red",
  "fill": "red"
}

13. 心形

v1.0.0

字段名称默认值字段解释数据类型是否必填可选值备注
type"heart"图的类型string"heart"
cx0圆心横坐标number
cy0圆心纵坐标number
width0心形宽number
height0心形高number

示例

json
{
  "type": "heart",
  "cx": 100,
  "cy": 100,
  "width": 50,
  "height": 50,
  "stroke": "yellow",
  "fill": "yellow"
}

14. 正多边形

v1.0.0

字段名称默认值字段解释数据类型是否必填可选值备注
type"isogon"图的类型string"isogon"
x0圆心横坐标number
y0圆心纵坐标number
r0半径number
n0边数number

示例

json
{
  "type": "isogon",
  "x": 400,
  "y": 400,
  "r": 50,
  "n": 5
}

15. 玫瑰线

v1.0.0

字段名称默认值字段解释数据类型是否必填可选值备注
type"rose"图的类型string"rose"
cx0圆心横坐标number
cy0圆心纵坐标number
r[]半径number[]
n0花瓣数number
k1玫瑰线参数number

示例

json
{
  "type": "rose",
  "cx": 600,
  "cy": 400,
  "n": 2,
  "r": [100, 120, 140, 160, 200, 220, 240, 260, 280],
  "k": 5,
  "stroke": "green"
}

16. 星形

v1.0.0

字段名称默认值字段解释数据类型是否必填可选值备注
type"star"图的类型string"star"
cx0圆心横坐标number
cy0圆心纵坐标number
r0半径number
n0瓣数number
r00内半径number

示例

json
{
  "type": "star",
  "cx": 100,
  "cy": 100,
  "n": 5,
  "r": 100,
  "r0": 50,
  "stroke": "red",
  "fill": "red"
}