12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- <!--
- * @Description:
- * @Version: 1.0
- * @Autor: zhuyijun
- * @Date: 2022-02-11 15:01:12
- * @LastEditTime: 2022-02-17 13:38:10
- -->
- <template>
- <div>
- <!-- 面包屑导航区 -->
- <el-breadcrumb separator-class="el-icon-arrow-right">
- <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
- <el-breadcrumb-item>数据统计</el-breadcrumb-item>
- <el-breadcrumb-item>数据报表</el-breadcrumb-item>
- </el-breadcrumb>
- <el-card>
- <div id="main"
- style="width: 750px;height:400px;">
- </div>
- </el-card>
- </div>
- </template>
- <script>
- // 导入echarts
- import * as echarts from 'echarts'
- import _ from 'lodash'
- export default {
- data () {
- return {
- 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'
- }
- ]
- }
- }
- },
- //执行到mounted函数,此时页面上的元素已经渲染好了
- async mounted () {
- //3. 基于准备好的dom,初始化echarts实例
- var myChart = echarts.init(document.getElementById('main'))
- const { data: res } = await this.$http.get('reports/type/1')
- if (res.meta.status !== 200) {
- return this.$message.error(res.meta.msg)
- }
- //4. 准备数据和配置项
- const result = _.merge(this.options, res.data)
- //5. 绘制图表
- myChart.setOption(result)
- }
- }
- </script>
- <style lang="less" scoped>
- #main {
- height: 500px;
- width: 100%;
- }
- </style>
|