Report.vue 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <!--
  2. * @Description:
  3. * @Version: 1.0
  4. * @Autor: zhuyijun
  5. * @Date: 2022-02-11 15:01:12
  6. * @LastEditTime: 2022-02-17 13:38:10
  7. -->
  8. <template>
  9. <div>
  10. <!-- 面包屑导航区 -->
  11. <el-breadcrumb separator-class="el-icon-arrow-right">
  12. <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
  13. <el-breadcrumb-item>数据统计</el-breadcrumb-item>
  14. <el-breadcrumb-item>数据报表</el-breadcrumb-item>
  15. </el-breadcrumb>
  16. <el-card>
  17. <div id="main"
  18. style="width: 750px;height:400px;">
  19. </div>
  20. </el-card>
  21. </div>
  22. </template>
  23. <script>
  24. // 导入echarts
  25. import * as echarts from 'echarts'
  26. import _ from 'lodash'
  27. export default {
  28. data () {
  29. return {
  30. options: {
  31. title: {
  32. text: '用户来源'
  33. },
  34. tooltip: {
  35. trigger: 'axis',
  36. axisPointer: {
  37. type: 'cross',
  38. label: {
  39. backgroundColor: '#E9EEF3'
  40. }
  41. }
  42. },
  43. grid: {
  44. left: '3%',
  45. right: '4%',
  46. bottom: '3%',
  47. containLabel: true
  48. },
  49. xAxis: [
  50. {
  51. boundaryGap: false
  52. }
  53. ],
  54. yAxis: [
  55. {
  56. type: 'value'
  57. }
  58. ]
  59. }
  60. }
  61. },
  62. //执行到mounted函数,此时页面上的元素已经渲染好了
  63. async mounted () {
  64. //3. 基于准备好的dom,初始化echarts实例
  65. var myChart = echarts.init(document.getElementById('main'))
  66. const { data: res } = await this.$http.get('reports/type/1')
  67. if (res.meta.status !== 200) {
  68. return this.$message.error(res.meta.msg)
  69. }
  70. //4. 准备数据和配置项
  71. const result = _.merge(this.options, res.data)
  72. //5. 绘制图表
  73. myChart.setOption(result)
  74. }
  75. }
  76. </script>
  77. <style lang="less" scoped>
  78. #main {
  79. height: 500px;
  80. width: 100%;
  81. }
  82. </style>