小猫咪心好痛 2022-09-09 14:42 采纳率: 88.9%
浏览 87
已结题

vue添加多个echart组件

怎么把好几个echart柱状图、饼状图放在一个vue里面?页面也没报错,就是显示不出来
vue代码如下:

<template>
  <div class="myChart">
  <div id="barChart" :style="{width: '800px', height: '600px'}">
  </div>
    <div id="pieChart" :style="{width: '800px', height: '600px'}">
    </div>
  </div>
</template>
<script>
export default{
  name: 'ECharts',
  mounted() {
    this.myChart1();
    this.myChart2();
  },
  methods:{
    myChart1()
    {
      // 基于准备好的dom,初始化echarts实例
      let myChart1 = this.$echarts.init(document.getElementById('barChart'))
      myChart1.option = {
        title: {
          text: '水果销量统计',
          left: 'center',
          top: 20,
          textStyle: {
            color: '#555555'
          }
        },
        tooltip: {},
        xAxis: {
          data: [
            "苹果",
            "香蕉",
            "橘子",
            "火龙果",
            "葡萄",
            "西瓜"
          ]
        },
        yAxis: {},
        series: [{
          name: '销量',
          type: 'bar',
          data: [
            {
              value: 333,
              itemStyle: {
                color: "#3fb1e3"
              }
            },
            {
              value: 133,
              itemStyle: {
                color: "#c4ebad"
              }
            },
            {
              value: 99,
              itemStyle: {
                color: "#c4ebad"
              }
            },
            {
              value: 222,
              itemStyle: {
                color: "#6be6c1"
              }
            },
            {
              value: 399,
              itemStyle: {
                color: "#3fb1e3"
              }
            },
            {
              value: 123,
              itemStyle: {
                color: "#c4ebad"
              }
            }
          ]
        }]
      }
    },
    myChart2()
    {
      let myChart2 = this.$echarts.init(document.getElementById('pieChart'))
      myChart2.option = {
        backgroundColor: '#2c343c',
        title: {
          text: 'Customized Pie',
          left: 'center',
          top: 20,
          textStyle: {
            color: '#ccc'
          }
        },
        tooltip: {
          trigger: 'item'
        },
        visualMap: {
          show: false,
          min: 80,
          max: 600,
          inRange: {
            colorLightness: [0, 1]
          }
        },
        series: [
          {
            name: 'Access From',
            type: 'pie',
            radius: '55%',
            center: ['50%', '50%'],
            data: [
              {value: 335, name: 'Direct'},
              {value: 310, name: 'Email'},
              {value: 274, name: 'Union Ads'},
              {value: 235, name: 'Video Ads'},
              {value: 400, name: 'Search Engine'}
            ].sort(function (a, b) {
              return a.value - b.value;
            }),
            roseType: 'radius',
            label: {
              color: 'rgba(255, 255, 255, 0.3)'
            },
            labelLine: {
              lineStyle: {
                color: 'rgba(255, 255, 255, 0.3)'
              },
              smooth: 0.2,
              length: 10,
              length2: 20
            },
            itemStyle: {
              color: '#c23531',
              shadowBlur: 200,
              shadowColor: 'rgba(0, 0, 0, 0.5)'
            },
            animationType: 'scale',
            animationEasing: 'elasticOut',
            animationDelay: function (idx) {
              return Math.random() * 200;
            }
          }
        ]
      }
    }
  },
}
</script>


  • 写回答

3条回答 默认 最新

  • 关注

    img

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
  • 崽崽的谷雨 2022-09-09 15:05
    关注
    评论
  • CSDN-Ada助手 CSDN-AI 官方账号 2022-09-09 15:24
    关注
    评论
查看更多回答(2条)

报告相同问题?

问题事件

  • 系统已结题 9月17日
  • 已采纳回答 9月9日
  • 修改了问题 9月9日
  • 创建了问题 9月9日

悬赏问题

  • ¥15 询问MYSQL查询SQLSERVER数据表并比较差异后,更新MYSQL的数据表
  • ¥15 关于#前端#的问题,请各位专家解答!
  • ¥15 最小生成树问题 Prim算法和Kruskal算法
  • ¥25 医院住院病人呼叫器设计
  • ¥15 不想和现在的团队合作了,怎么避免他们对程序动手脚
  • ¥30 c++类和数组实验代码
  • ¥20 C语言字符串不区分大小写字典排序相关问题
  • ¥15 关于#python#的问题:我希望通过逆向技术爬取1688搜索页下滑加载的数据
  • ¥15 关于Linux的终端里,模拟实现一个带口令保护的屏保程序遇到的输入输出的问题!(语言-c语言)
  • ¥30 请问,这个嵌入式Linux系统谁能帮我分析一下,crc检验区域在哪,不是内核的校验,内核校验我已经找到了