Appearance
ECharts
说明
ECharts封装,不需要再单独引入Echarts,只需给定配置即可,使用请参考官方文档
基本配置项
tooltip
配置提示框组件,显示提示信息。
js
tooltip: {
trigger: 'item', // 数据项图形触发
formatter: '{a} <br/>{b}: {c} ({d}%)' // 格式化显示内容
}
1
2
3
4
2
3
4
legend
配置图例组件,展示系列名称,提供点击筛选的功能。
js
legend: {
orient: 'horizontal', // 水平排列
left: 'center', // 居中显示
data: ['系列1', '系列2', '系列3'] // 图例项
}
1
2
3
4
5
2
3
4
5
xAxis
/ yAxis
(Array | Object)
配置 x 轴或 y 轴的属性。
js
xAxis: {
type: 'category', // 类目轴
data: ['A', 'B', 'C', 'D'] // 类目数据
}
1
2
3
4
2
3
4
series
(Array)
配置图表的具体数据系列和类型。
js
series: [
{
name: '系列1',
type: 'bar', // 设置为条形图
data: [120, 200, 150, 80] // 数据项
}
]
1
2
3
4
5
6
7
2
3
4
5
6
7
grid
(Object)
配置图表的网格区域,控制图表的位置和大小。
js
grid: {
left: '10%', // 距离左侧的距离
right: '10%', // 距离右侧的距离
bottom: '10%' // 距离底部的距离
}
1
2
3
4
5
2
3
4
5
color
(Array)
配置图表的配色方案,支持多种颜色。
js
color: ['#5470C6', '#91CC75', '#EE6666']
1
title
(Object)
配置标题组件,控制图表的主标题和副标题。
js
title: {
text: 'ECharts 示例', // 主标题
subtext: '副标题', // 副标题
left: 'center' // 标题居中
}
1
2
3
4
5
2
3
4
5
toolbox
(Object)
配置工具栏,可以包括保存、数据视图等功能。
js
toolbox: {
show: true, // 显示工具栏
feature: {
saveAsImage: { // 保存为图片
show: true
}
}
}
1
2
3
4
5
6
7
8
2
3
4
5
6
7
8
animation
(Boolean)
控制是否开启动画效果。
js
animation: true // 开启动画
1
backgroundColor
(String)
设置图表背景色。
js
backgroundColor: '#f4f4f4' // 设置浅灰色背景
1
responsive
(Boolean)
控制图表是否响应窗口大小变化。
js
responsive: true // 自动响应窗口大小变化
1
polar
(Object)
配置极坐标系相关的设置。
js
polar: {
radius: '60%' // 设置极坐标半径
}
1
2
3
2
3
这些参数是构建 ECharts 配置项时的常见元素。不同的图表类型(如柱状图、折线图、饼图等)可能会有更具体的配置选项,具体可以参考配置项。
使用示例
vue
<template>
<div>
<ECharts :options= "option" height="400px" width="600px"></ECharts>
</div>
</template>
<script setup lang="ts">
import ECharts from "liyao-vue-common"
//自行修改...
const option = {
xAxis: {
data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
},
yAxis: {},
series: [
{
type: 'bar',
data: [23, 24, 18, 25, 27, 28, 25]
}
]
}
</script>
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
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25