要在文本前面加一个圆形图例,可以使用 ECharts 中的 `graphic` 组件来实现。
以下是一个示例代码:
```javascript
option = {
// ...
graphic: [
{
type: 'circle',
left: '50%',
top: '8%',
shape: {
cx: 5,
cy: 5,
r: 5
},
style: {
fill: '#1B6DEA'
}
}
],
series: [
{
// ...
label: {
show: true,
position: 'insideLeft',
formatter: '{a|闪信数量:} {b|' + anomalyCountNum + '}{c|/}' + testCountNum,
rich: {
a: {
fontSize: 16,
color: '#666666',
fontWeight: 'bold'
},
b: {
fontSize: 16,
color: '#1B6DEA',
fontWeight: 'bold'
},
c: {
fontSize: 16,
color: '#999999',
fontWeight: 'bold'
}
}
},
// ...
}
]
};
```
在上面的代码中,我们使用了 `graphic` 组件添加了一个圆形图例,然后在 `label` 的 `formatter` 属性中使用了 `{a|}`、`{b|}` 和 `{c|}` 来设置不同样式的文本。其中,`{a|}` 表示使用 `rich` 中名为 `a` 的样式,`{b|}` 表示使用 `rich` 中名为 `b` 的样式,`{c|}` 表示使用 `rich` 中名为 `c` 的样式。
注意,`graphic` 组件需要放在 `series` 外面,而 `label` 需要放在对应的 `series` 中。