vue--跟echarts的结合

在这里插入图片描述
main文件写入:

// 引入echarts
import echarts from 'echarts'

window.echarts = require('echarts');

Vue.prototype.$echarts = echarts

html

 <div class="maina">
        <div id="main"></div>
        <div id="main02"></div>
      </div>

js

  //echarts数据
    load02() {
      let _this = this;

      this.$httpxu({
        method: "get",
        url: `/getScreenSumData.do`
      })
        .then(function(response) {
          console.log("老方法", response.data);

          _this.zzt(response.data.callData);
          _this.xxt(response.data.daycallData);
        })
        .catch(function(error) {});
    },
   // 柱状图
    zzt(data) {
      // if (this.myChart != null) {
      //   this.myChart.dispose();
      // }
      let _this = this;
      console.log(1);
      let echartdiv = document.getElementById("main");
      this.myChart = this.$echarts.init(echartdiv);
      console.log("柱状图", data);

      for (let i in data) {
        let a = data[i].dateval.slice(-2);
        let b = a + "号";
        let c = data[i].num;
        console.log("b", b);

        _this.dataday.push(b);
        _this.datadaynum.push(c);
      }

      let option = {
        title: {
          text: "一周呼叫数量统计"
        },
        tooltip: {
          trigger: "axis",
          axisPointer: {
            type: "cross",
            crossStyle: {
              color: "#999"
            }
          }
        },
        toolbox: {
          feature: {
            dataView: { show: false, readOnly: false },
            magicType: { show: false, type: ["bar"] }
          }
        },
        legend: {
          data: ["一周量"]
        },
        xAxis: [
          {
            type: "category",
            // data: ["15号", "16号", "17号", "18号", "19号", "20号", "21号"],
            data: _this.dataday,
            axisPointer: {
              type: "shadow"
            },
            axisLabel: {
              textStyle: {
                color: "#999"
              }
            }
          }
        ],
        yAxis: [
          {
            type: "value",
            name: "(次)",
            min: 0,
            max: 2500,
            interval: 500,
            axisLabel: {
              formatter: "{value}",
              textStyle: {
                color: "#999"
              }
            }
          }
        ],

        series: [
          {
            name: "呼叫量",
            type: "bar",
            // data: [2000, 1300, 2400, 1550, 1800, 1100, 1000],
            data: _this.datadaynum,
            barGap: "-100%",
            barCategoryGap: "80%",
            itemStyle: {
              color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
                { offset: 0, color: "#9ED06C" },
                { offset: 0.5, color: "#78C46F" },
                { offset: 1, color: "#4DB772" }
              ])
            }
          }
        ]
      };

      this.myChart.setOption(option);
    },
    // 线形图
    xxt(data) {
      let _this = this;
      let echartdiv = document.getElementById("main02");
      this.myChart = this.$echarts.init(echartdiv);

      for (let j in data) {
        let d = data[j].timeval;
        let e = d + "点";
        let f = data[j].num;
        _this.datahour.push(e);
        _this.datahournum.push(f);
      }

      let option = {
        title: {
          text: "1小时呼叫次数"
        },
        tooltip: {
          trigger: "axis",
          axisPointer: {
            type: "cross",
            crossStyle: {
              color: "#999"
            }
          }
        },
        toolbox: {
          feature: {
            dataView: { show: false, readOnly: false },
            magicType: { show: false, type: ["bar"] }
          }
        },
        legend: {
          data: ["一周量"]
        },
        xAxis: [
          {
            type: "category",
            // data: [
            //   "1点",
            //   "2点",
            //   "3点",
            //   "4点",
            //   "5点",
            //   "6点",
            //   "7点",
            //   "8点",
            //   "9点",
            //   "10点",
            //   "11点",
            //   "12点"
            // ],
            data: _this.datahour,
            axisPointer: {
              type: "shadow"
            },
            axisLabel: {
              textStyle: {
                color: "#999"
              }
            }
          }
        ],
        yAxis: [
          {
            type: "value",
            name: "(次)",
            min: 0,
            max: 1000,
            interval: 200,
            axisLabel: {
              formatter: "{value}",
              textStyle: {
                color: "#999"
              }
            }
          }
        ],

        series: [
          {
            // data: [200, 580, 300, 600, 650, 690, 650, 540, 490, 320, 800, 600],
            data: _this.datahournum,
            type: "line",
            smooth: true,
            lineStyle: {
              color: "#19EC76",
              width: 3
            }
          }
        ]
      };

      this.myChart.setOption(option);
    },
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值