关于echarts:vue-引入-echart

46次阅读

共计 723 个字符,预计需要花费 2 分钟才能阅读完成。

  1. 装置 echarts 依赖 npm install echarts –save
  2. 在 main.js 中全局中援用
import echarts from 'echarts'
Vue.prototype.$echarts = echarts
<div id="main" style="width:100%;height:376px"></div>
 mounted(){this.getEchartData()  
    },


   methods: {getEchartData() {var chartDom = document.getElementById('main');
          var myChart = echarts.init(chartDom);
          var option;
          
          option = {
              title: {
                  text: '某站点用户拜访起源',
                  subtext: '纯属虚构',
                  left: 'center'
              },
              tooltip: {trigger: 'item'},
              legend: {
                  orient: 'vertical',
                  left: 'left',
              },
              series: [
                  {
                      name: '拜访起源',
                      type: 'pie',
                      radius: '50%',
                      data: [{value: 1048, name: '搜索引擎'},
                          {value: 735, name: '间接拜访'},
                          {value: 580, name: '邮件营销'},
                          {value: 484, name: '联盟广告'},
                          {value: 300, name: '视频广告'}
                      ],
                      emphasis: {
                          itemStyle: {
                              shadowBlur: 10,
                              shadowOffsetX: 0,
                              shadowColor: 'rgba(0, 0, 0, 0.5)'
                          }
                      }
                  }
              ]
          };
          
          option && myChart.setOption(option);  
    }
  },

正文完
 0