数据报表相关功能的开发
先将页面渲染出来
安装echarts
cnpm install echarts@4.1.0 --save
官网:https://echarts.apache.org/zh/index.html
使用:分为5个步骤
<template>
<div>
<!-- 面包屑导航区域。先要在plugins/element.js里面导入导入注册-->
<el-breadcrumb separator-class="el-icon-arrow-right">
<el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item> <!-- 点击首页的时候,跳转到/home-->
<el-breadcrumb-item>数据统计</el-breadcrumb-item>
<el-breadcrumb-item>数据报表</el-breadcrumb-item>
</el-breadcrumb>
<!--卡片视图区域-->
<el-card>
<!-- 2、为 ECharts 准备一个定义了宽高的 DOM -->
<div id="main" style="width: 600px;height:400px;"></div>
</el-card>
</div>
</template>
<script>
// 1、导入echarts
import echarts from 'echarts'
export default {
data () {
},
created () {
},
// 此时页面上的元素,已经被渲染完毕了
mounted () {
// 3、基于准备好的dom,初始化echarts实例
var myChart = echarts.init(document.getElementById('main'))
// 4、准备数据和配置项
var option = {
title: {
text: 'ECharts 入门示例'
},
tooltip: {},
legend: {
data: ['销量']
},
xAxis: {
data: ['衬衫', '羊毛衫', '雪纺衫', '裤子', '高跟鞋', '袜子']
},
yAxis: {},
series: [
{
name: '销量',
type: 'bar',
data: [5, 20, 36, 10, 10, 20]
}
]
}
// 5、展示数据
myChart.setOption(option)
},
methods: {}
}
</script>
<style scoped>
</style>
获取报表的数据,替换图表数据
现在没有鼠标跟随的效果,实际效果是需要的
需要把数据重新拼接一下,下面就是要合并的数据
//需要跟请求的折线图数据合并的options
options: {
title: {
text: '用户来源'
},
tooltip: {
trigger: 'axis',
axisPointer: {
type: 'cross',
label: {
backgroundColor: '#E9EEF3'
}
}
},
grid: {
left: '3%',
right: '4%',
bottom: '3%',
containLabel: true
},
xAxis: [
{
boundaryGap: false
}
],
yAxis: [
{
type: 'value'
}
]
}
现在就是需要将两个对象合并起来,得到一个新的对象