大白莎 2022-04-15 15:40 采纳率: 60%
浏览 27
已结题

vue使用echart报错

img

在另一个页面使用el-select没问题,在这就报错


<template>
  <div>
    <div>
      <el-select v-model="value" placeholder="请选择" @change="showchart">
        <el-option
          v-for="item in options"
          :key="item.value"
          :label="item.label"
          :value="item.value"
        >
        </el-option>
      </el-select>
    </div>
    <div id="main" style="width: 100%; height: 100%"></div>
  </div>
</template>

<script>
import * as echarts from "echarts";
import { highwayChart } from "../../api/api.js";
export default {
  data() {
    return {
      data2020: {
        segname: [],
        voc1: [],
        voc2: [],
        voc3: [],
        voc4: [],
        tvc: [],
        vot1: [],
        vot2: [],
        vot3: [],
        vot4: [],
        vot5: [],
        vot6: [],
        tvt: [],
        tv: [],
        year: "",
      },
      options: [
        {
          value: "京港澳高速(鄂北-鄂南)",
          label: "京港澳高速(鄂北-鄂南)",
        },
        {
          value: "G4201武汉绕城高速公路",
          label: "G4201武汉绕城高速公路",
        },
        {
          value: "二广高速",
          label: "二广高速",
        },
        {
          value: "岱黄高速",
          label: "岱黄高速",
        },
        {
          value: "汉孝高速",
          label: "汉孝高速",
        },
        {
          value: "鸦猇高速",
          label: "鸦猇高速",
        },
        ,
        {
          value: "三峡高速",
          label: "三峡高速",
        },
        {
          value: "汉蔡高速",
          label: "汉蔡高速",
        },
        {
          value: "许广高速",
          label: "许广高速",
        },
        {
          value: "沪蓉高速",
          label: "沪蓉高速",
        },
        {
          value: "武鄂高速",
          label: "武鄂高速",
        },
        ,
        {
          value: "沪渝高速",
          label: "沪渝高速",
        },
        {
          value: "翻坝高速",
          label: "翻坝高速",
        },
        {
          value: "天河机场北连接线",
          label: "天河机场北连接线",
        },
        {
          value: "机场二高速",
          label: "机场二高速",
        },
      ],
      value: "二广高速",
    };
  },
  mounted() {
    this.showchart();
  },
  created() {},
  methods: {
    showchart() {
      highwayChart({ hwnm: this.value })
        .then((res) => {
          this.data2020.segname = res[0];
          this.data2020.voc1 = res[1];
          this.data2020.voc2 = res[2];
          this.data2020.voc3 = res[3];
          this.data2020.voc4 = res[4];
          this.data2020.tvc = res[5];
          this.data2020.vot1 = res[6];
          this.data2020.vot2 = res[7];
          this.data2020.vot3 = res[8];
          this.data2020.vot4 = res[9];
          this.data2020.vot5 = res[10];
          this.data2020.vot6 = res[11];
          this.data2020.tvt = res[12];
          this.data2020.tv = res[13];
          this.data2020.year = res[14];

          this.chartLine = echarts.init(document.getElementById("main"));

          var option = {
            baseOption: {
              timeline: {
                axisType: "category",
                autoPlay: false,
                playInterval: 1000,
                data: [
                  "2011-01-01",
                  "2012-01-01",
                  "2013-01-01",
                  "2014-01-01",
                  "2015-01-01",
                  "2016-01-01",
                  "2017-01-01",
                  "2018-01-01",
                  "2019-01-01",
                  "2020-01-01",
                ],
                label: {
                  formatter: function (s) {
                    return new Date(s).getFullYear();
                  },
                },
              },
              tooltip: {},
              legend: {
                left: "right",
                data: [
                  "客车1",
                  "客车2",
                  "客车3",
                  "客车4",
                  "货车1",
                  "货车2",
                  "货车3",
                  "货车4",
                  "货车5",
                  "货车6",
                ],
              },
              calculable: true,
              grid: {
                left: "2%",
                right: "5%",
                top: "10%",
                bottom: "10%",
                containLabel: true,
                tooltip: {
                  trigger: "axis",
                  axisPointer: {
                    type: "shadow",
                    label: {
                      show: true,
                      formatter: function (params) {
                        return params.value.replace("\n", "");
                      },
                    },
                  },
                },
              },
              yAxis: [
                {
                  type: "category",
                  axisLabel: { interval: 0 },
                  data: this.data2020.segname,
                  splitLine: { show: false },
                  offset: 10,
                },
              ],
              xAxis: [
                {
                  type: "value",
                  name: "车流量",
                },
              ],
              //  柱状提示
              series: [
                {
                  name: "客车1",
                  type: "bar",
                  stack: "客车",
                  emphasis: {
                    focus: "series",
                  },
                },
                {
                  name: "客车2",
                  type: "bar",
                  stack: "客车",
                  emphasis: {
                    focus: "series",
                  },
                },
                {
                  name: "客车3",
                  type: "bar",
                  stack: "客车",
                  emphasis: {
                    focus: "series",
                  },
                },
                {
                  name: "客车4",
                  type: "bar",
                  stack: "客车",
                  emphasis: {
                    focus: "series",
                  },
                },
                {
                  name: "货车1",
                  type: "bar",
                  stack: "货车",
                  emphasis: {
                    focus: "series",
                  },
                },
                {
                  name: "货车2",
                  type: "bar",
                  stack: "货车",
                  emphasis: {
                    focus: "series",
                  },
                },
                {
                  name: "货车3",
                  type: "bar",
                  stack: "货车",
                  emphasis: {
                    focus: "series",
                  },
                },
                {
                  name: "货车4",
                  type: "bar",
                  stack: "货车",
                  emphasis: {
                    focus: "series",
                  },
                },
                {
                  name: "货车5",
                  type: "bar",
                  stack: "货车",
                  emphasis: {
                    focus: "series",
                  },
                },
                {
                  name: "货车6",
                  type: "bar",
                  stack: "货车",
                  emphasis: {
                    focus: "series",
                  },
                },
                {
                  name: "车流量占比",
                  type: "pie",
                  center: ["85%", "30%"],
                  radius: "28%",
                  z: 100,
                },
              ],
            },
            options: [
              {
                title: { text: "2020车流量" },
                series: [
                  { data: this.data2020.voc1 },
                  { data: this.data2020.voc2 },
                  { data: this.data2020.voc3 },
                  { data: this.data2020.voc4 },
                  { data: this.data2020.vot1 },
                  { data: this.data2020.vot2 },
                  { data: this.data2020.vot3 },
                  { data: this.data2020.vot4 },
                  { data: this.data2020.vot5 },
                  { data: this.data2020.vot6 },
                  {
                    data: [
                      { name: "客车总流量", value: this.data2020.tvc },
                      { name: "货车总流量", value: this.data2020.tvt },
                    ],
                  },
                ],
              },
            ],
          };

          this.chartLine.setOption(option);
          window.onresize = myChart.resize;
        })
        .catch((error) => {
          this.$message.error({
            message: error,
          });
        });
    },
  },
};
</script>
  • 写回答

2条回答 默认 最新

  • 面向百度编程cv 2022-04-15 16:27
    关注

    {
    value: "京港澳高速(鄂北-鄂南)",
    label: "京港澳高速(鄂北-鄂南)",
    },
    value 要数字 1 ‘1’ 都行

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 5月3日
  • 已采纳回答 4月25日
  • 创建了问题 4月15日

悬赏问题

  • ¥15 x趋于0时tanx-sinx极限可以拆开算吗
  • ¥500 把面具戴到人脸上,请大家贡献智慧
  • ¥15 任意一个散点图自己下载其js脚本文件并做成独立的案例页面,不要作在线的,要离线状态。
  • ¥15 各位 帮我看看如何写代码,打出来的图形要和如下图呈现的一样,急
  • ¥30 c#打开word开启修订并实时显示批注
  • ¥15 如何解决ldsc的这条报错/index error
  • ¥15 VS2022+WDK驱动开发环境
  • ¥30 关于#java#的问题,请各位专家解答!
  • ¥30 vue+element根据数据循环生成多个table,如何实现最后一列 平均分合并
  • ¥20 pcf8563时钟芯片不启振