vue 使用echarts

7 篇文章 0 订阅
1 篇文章 0 订阅

效果图
在这里插入图片描述

<template>
   <div id="report" style="width: 1200px;height: 700px;"></div>
</template>


<script>
// 引入基本模板
import * as echarts from 'echarts/lib/echarts'
// 引入柱状图组件
// 引入提示框和title组件
import {GridComponent, LegendComponent, ToolboxComponent,TooltipComponent,TitleComponent} from 'echarts/components';
import {LineChart,BarChart } from 'echarts/charts';
echarts.use([LineChart,BarChart,GridComponent, LegendComponent, ToolboxComponent,TooltipComponent,TitleComponent]);


let report;

export default {
  name: 'WxReport',
  components: {},
  data() {
    return {
    }
  },
  mounted() {
    if (!!report) {
      console.log("dispose")
      report.dispose();//销毁
    }
    this.$nextTick(()=>{
      this.drawLine();
    })
  },
  created() {
    
  },
  methods: {
    drawLine() {
      // 基于准备好的dom,初始化echarts实例
      report = echarts.init(document.getElementById('report'))
      // 绘制图表
      report.setOption({
        tooltip: {
          trigger: 'axis',
          axisPointer: {
            type: 'cross',
            crossStyle: {
              color: '#999'
            }
          }
        },
        toolbox: {
          feature: {
            saveAsImage: {show: true}
          }
        },
        legend: {
          data: ['20s', '30s', '60s', '平均响应']
        },
        xAxis: [
          {
            type: 'category',
            data: ['9', '10', '11', '12', '13', '14', '15', '16', '17', '18'],
            axisPointer: {
              type: 'shadow'
            }
          }
        ],
        yAxis: [
          {
            type: 'value',
            name: '响应及时率',
            min: 0,
            max: 100,
            interval: 10,
            axisLabel: {
              formatter: '{value} %'
            }
          },
          {
            type: 'value',
            name: '平均响应',
            min: 0,
            max: 60,
            interval: 20,
            axisLabel: {
              formatter: '{value} s'
            }
          }
        ],
        series: [
          {
            name: '20s',
            type: 'bar',
            tooltip: {
              valueFormatter: function (value) {
                return value + ' %';
              }
            },
            data: [75, 70, 68, 65, 79, 65, 25, 57, 63, 59, 75]
          },
          {
            name: '30s',
            type: 'bar',
            tooltip: {
              valueFormatter: function (value) {
                return value + ' %';
              }
            },
            data: [85, 80.89, 78.92, 75.5, 89.3, 75.2, 35.3, 67.4, 73, 69.5, 85]
          },
          {
            name: '60s',
            type: 'bar',
            tooltip: {
              valueFormatter: function (value) {
                return value + ' %';
              }
            },
            data: [95, 90.89, 88.92, 85.5, 99.3, 85.2, 45.3, 77.4, 83.0, 79.5, 95]
          },
          {
            name: '平均响应',
            type: 'line',
            yAxisIndex: 1,
            tooltip: {
              valueFormatter: function (value) {
                return value + ' s';
              }
            },
            data: [35, 30, 28, 25, 39, 25, 25, 17, 23, 19, 35]
          }
        ]
      });
    }
  }
}
</script>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值