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

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

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

报告相同问题?

问题事件

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

悬赏问题

  • ¥20 iqoo11 如何下载安装工程模式
  • ¥15 本题的答案是不是有问题
  • ¥15 关于#r语言#的问题:(svydesign)为什么在一个大的数据集中抽取了一个小数据集
  • ¥15 C++使用Gunplot
  • ¥15 这个电路是如何实现路灯控制器的,原理是什么,怎么求解灯亮起后熄灭的时间如图?
  • ¥15 matlab数字图像处理频率域滤波
  • ¥15 在abaqus做了二维正交切削模型,给刀具添加了超声振动条件后输出切削力为什么比普通切削增大这么多
  • ¥15 ELGamal和paillier计算效率谁快?
  • ¥15 蓝桥杯单片机第十三届第一场,整点继电器吸合,5s后断开出现了问题
  • ¥15 file converter 转换格式失败 报错 Error marking filters as finished,如何解决?