vue 中引用echarts

安装echarts  依赖

npm install echarts -S

全局引入

import echarts from 'echarts'

HTML部分

<div id="myChartId" style="height:500px;width:1000px"></div>

初始化echarts

created: function () {
    this.initChart();
},

chart数据

methods: {
  initChart() {
    this.chart = echarts.init(document.getElementById("myChartId"));
    // 把配置和数据放这里
    this.chart.setOption({
        color: ['#3398DB'],
        tooltip: {
            trigger: 'axis',
            axisPointer: { // 坐标轴指示器,坐标轴触发有效
                type: 'shadow' // 默认为直线,可选为:'line' | 'shadow'
            }
        },
        grid: {
            left: '3%',
            right: '4%',
            bottom: '3%',
            containLabel: true
        },
        xAxis: [{
            type: 'category',
            data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
            axisTick: {
                alignWithLabel: true
            }
        }],
        yAxis: [{
            type: 'value'
        }],
        series: [{
            name: '直接访问',
            type: 'bar',
            barWidth: '60%',
            data: [10, 52, 200, 334, 390, 330, 220]
        }]
    })
  }
}

猜你喜欢

转载自blog.csdn.net/WANG_CODER/article/details/82144093