菜单 学习猿地 - LMONKEY

VIP

开通学习猿地VIP

尊享10项VIP特权 持续新增

知识通关挑战

打卡带练!告别无效练习

接私单赚外块

VIP优先接,累计金额超百万

学习猿地私房课免费学

大厂实战课仅对VIP开放

你的一对一导师

每月可免费咨询大牛30次

领取更多软件工程师实用特权

入驻

ECharts grid组件配置 坐标轴指示器线条样式设置

原创
05/13 14:22 更新

对 ECharts 中的坐标轴指示器的线条进行设置的时候,会有两种情况:

  • axisPointer.type 为 ‘line’ 时;

  • axisPointer.type 为 ‘cross’ 时;

grid.tooltip.axisPointer.lineStyle   |   Object


axisPointer.type 为 ‘line’ 时有效。

grid.tooltip.axisPointer.lineStyle.color   |   Color

[ default: #555 ]

线的颜色。

颜色可以使用 RGB 表示,比如 ‘rgb(128, 128, 128)’,如果想要加上 alpha 通道表示不透明度,可以使用 RGBA,比如 ‘rgba(128, 128, 128, 0.5)’,也可以使用十六进制格式,比如 ‘#ccc’。除了纯色之外颜色也支持渐变色和纹理填充

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
// 线性渐变,前四个参数分别是 x0, y0, x2, y2, 范围从 0 - 1,相当于在图形包围盒中的百分比,如果 globalCoord 为 `true`,则该四个值是绝对的像素位置 color: { type: 'linear', x: 0, y: 0, x2: 0, y2: 1, colorStops: [{ offset: 0, color: 'red' // 0% 处的颜色 }, { offset: 1, color: 'blue' // 100% 处的颜色 }], globalCoord: false // 缺省为 false } // 径向渐变,前三个参数分别是圆心 x, y 和半径,取值同线性渐变 color: { type: 'radial', x: 0.5, y: 0.5, r: 0.5, colorStops: [{ offset: 0, color: 'red' // 0% 处的颜色 }, { offset: 1, color: 'blue' // 100% 处的颜色 }], globalCoord: false // 缺省为 false } // 纹理填充 color: { image: imageDom, // 支持为 HTMLImageElement, HTMLCanvasElement,不支持路径字符串 repeat: 'repeat' // 是否平铺, 可以是 'repeat-x', 'repeat-y', 'no-repeat' }

grid.tooltip.axisPointer.lineStyle.width   |   number

[ default: 1 ]

线宽。


grid.tooltip.axisPointer.lineStyle.type   |   string

[ default: solid ]

线的类型。

可选:

  • ‘solid’
  • ‘dashed’
  • ‘dotted’

grid.tooltip.axisPointer.lineStyle.shadowBlur   |   number

图形阴影的模糊大小。该属性配合 shadowColor,shadowOffsetX, shadowOffsetY 一起设置图形的阴影效果。

示例:

1
2
3
4
5
{ shadowColor: 'rgba(0, 0, 0, 0.5)', shadowBlur: 10 }

grid.tooltip.axisPointer.lineStyle.shadowColor   |   Color

阴影颜色。支持的格式同color。


grid.tooltip.axisPointer.lineStyle.shadowOffsetX   |   number

[ default: 0 ]

阴影水平方向上的偏移距离。


grid.tooltip.axisPointer.lineStyle.shadowOffsetY   |   number

[ default: 0 ]

阴影垂直方向上的偏移距离。


grid.tooltip.axisPointer.lineStyle.opacity   |   number

图形透明度。支持从 0 到 1 的数字,为 0 时不绘制该图形。

grid.tooltip.axisPointer.crossStyle   |   Object


axisPointer.type 为 ‘cross’ 时有效。

grid.tooltip.axisPointer.crossStyle.color   |   Color

[ default: #555 ]

线的颜色。

颜色可以使用 RGB 表示,比如 ‘rgb(128, 128, 128)’,如果想要加上 alpha 通道表示不透明度,可以使用 RGBA,比如 ‘rgba(128, 128, 128, 0.5)’,也可以使用十六进制格式,比如 ‘#ccc’。除了纯色之外颜色也支持渐变色和纹理填充

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// 线性渐变,前四个参数分别是 x0, y0, x2, y2, 范围从 0 - 1,相当于在图形包围盒中的百分比,如果 globalCoord 为 `true`,则该四个值是绝对的像素位置 color: { type: 'linear', x: 0, y: 0, x2: 0, y2: 1, colorStops: [{ offset: 0, color: 'red' // 0% 处的颜色 }, { offset: 1, color: 'blue' // 100% 处的颜色 }], globalCoord: false // 缺省为 false } // 径向渐变,前三个参数分别是圆心 x, y 和半径,取值同线性渐变 color: { type: 'radial', x: 0.5, y: 0.5, r: 0.5, colorStops: [{ offset: 0, color: 'red' // 0% 处的颜色 }, { offset: 1, color: 'blue' // 100% 处的颜色 }], globalCoord: false // 缺省为 false } // 纹理填充 color: { image: imageDom, // 支持为 HTMLImageElement, HTMLCanvasElement,不支持路径字符串 repeat: 'repeat' // 是否平铺, 可以是 'repeat-x', 'repeat-y', 'no-repeat' }

grid.tooltip.axisPointer.crossStyle.width   |   number

[ default: 1 ]

线宽。


grid.tooltip.axisPointer.crossStyle.type   |   string

[ default: dashed ]

线的类型。

可选:

  • ‘solid’
  • ‘dashed’
  • ‘dotted’

grid.tooltip.axisPointer.crossStyle.shadowBlur   |   number

图形阴影的模糊大小。该属性配合 shadowColor,shadowOffsetX, shadowOffsetY 一起设置图形的阴影效果。

示例:

1
2
3
4
5
{ shadowColor: 'rgba(0, 0, 0, 0.5)', shadowBlur: 10 }

grid.tooltip.axisPointer.crossStyle.shadowColor   |   Color

阴影颜色。支持的格式同color。


grid.tooltip.axisPointer.crossStyle.shadowOffsetX   |   number

[ default: 0 ]

阴影水平方向上的偏移距离。


grid.tooltip.axisPointer.crossStyle.shadowOffsetY   |   number

[ default: 0 ]

阴影垂直方向上的偏移距离。


grid.tooltip.axisPointer.crossStyle.opacity   |   number

图形透明度。支持从 0 到 1 的数字,为 0 时不绘制该图形。

综合评分:9.9 评分 请对本文进行纠错,及学习过程中有困难疑惑可在此进行讨论