第一步:打开ECharts官网,选择你需要的图表
https://echarts.apache.org/
第二部:npm安装,注意要在你vue工程的目录下,使用下列命令
npm i echarts -S
第三步:复制你选择的图表官方给出的对应代码
option = {
title: {
text: 'Stacked Line'
},
tooltip: {
trigger: 'axis'
},
legend: {
data: ['Email', 'Union Ads', 'Video Ads', 'Direct', 'Search Engine']
},
grid: {
left: '3%',
right: '4%',
bottom: '3%',
containLabel: true
},
toolbox: {
feature: {
saveAsImage: {}
}
},
xAxis: {
type: 'category',
boundaryGap: false,
data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
},
yAxis: {
type: 'value'
},
series: [
{
name: 'Email',
type: 'line',
stack: 'Total',
data: [120, 132, 101, 134, 90, 230, 210]
},
{
name: 'Union Ads',
type: 'line',
stack: 'Total',
data: [220, 182, 191, 234, 290, 330, 310]
},
{
name: 'Video Ads',
type: 'line',
stack: 'Total',
data: [150, 232, 201, 154, 190, 330, 410]
},
{
name: 'Direct',
type: 'line',
stack: 'Total',
data: [320, 332, 301, 334, 390, 330, 320]
},
{
name: 'Search Engine',
type: 'line',
stack: 'Total',
data: [820, 932, 901, 934, 1290, 1330, 1320]
}
]
};
第四步:定义echarts图表对应的dom元素(必须),在你的vue页面<template> 下
<el-card>
<div id="line" style="width: 100%; height: 400px"></div>
</el-card>
第五步:在你的mounted()方法你添加下列代码
var lineBox = echarts.init(document.getElementById('line'))
lineBox.setOption(option)
注意 :这里的 lineBox中的 ‘line’ 必须和第四步中id 的 ‘line’一致 option必须和你的第三步中的option一致
就可以了!!!