今天看了很多echarts的用法,但是业务需求和这些都不一样,没办法只能找官网看api了
什么话都不多说了,直接上代码
首先需要下载echarts
cnpm i echarts -s
其次,就是直接写就好了,注释基本都有
<template>
<div>
<!-- 图标容器 -->
<div id="main" style="width: 400px;height: 200px;"></div>
</div>
</template>
<script>
import echarts from 'echarts'
export default {
name:'echarts',
data() {
return {
charts: '',
// 定义的第一组数据
opinion: ["1", "3", "3", "4", "5"],
// 定义的第二组数据
opinionData: ["3", "1", "4", "0", "5",'2','0']
}
},
methods: {
// 封装方法,稍后执行
drawLine(id) {
//初始化echarts表格
this.charts = echarts.init(document.getElementById(id))
this.charts.setOption({
// 提示
tooltip: {
trigger: 'axis'
},
// 图例
legend: {
data: ['近七日收益']
},
// 网格大小,距离左,右,下的距离,类似于padding
grid: {
left: '2%',
right: '2%',
bottom: '2%',
containLabel: true
},
//横坐标的参数
xAxis: {
// 类型
type: 'category',
boundaryGap: false,
// 设置间隔
axisLabel:{
interval:0
},
// 横坐标内容
data: ["a","b","c","d","e"]
},
// 纵坐标参数
yAxis: {
type: 'value'
},
// 数据列表 可定义多个数据
series: [
{
name: '近七日收益',
// line为折线图类型 pie为饼图类型 bar为柱状图列表
type: 'line',
stack: '11',
itemStyle : {
normal : {
lineStyle:{
color:'#00FF00'
}
}
},
data: this.opinionData
},
{
name: '近七日收益',
type: 'line',
stack: '22',
data: this.opinion
}
]
})
}
},
//调用
mounted() {
this.$nextTick(function() {
this.drawLine('main')
})
}
}
</script>

微信图片_20200430170156.png

微信图片_20200430170149.png
欢迎提问