宋子宪博客

Vue整合echarts

npm 安装echarts

npm install echarts -S

安装好之后在<script>引入echarts

import * as echarts from 'echarts'

在template标签中引用

<div id="main" style="width: 100%; height: 400px;">/div>

export default中创建mounted页面元素渲染之后再触发

完整Vue代码

<template>
    <div id="main" style="width: 100%; height: 400px;">
    </div>
</template>

<script>
import * as echarts from 'echarts'

export default {
  name: "StudyIndex",
  data() {
    return {}
  },
  mounted() {
    var chartDom = document.getElementById('main');
    var myChart = echarts.init(chartDom);
    var option;


option = {
  xAxis: {
    type: 'category',
    data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
  },
  yAxis: {
    type: 'value'
  },
  series: [
    {
      data: [150, 230, 224, 218, 135, 147, 260],
      type: 'line'
    }
  ]
};
    myChart.setOption(option);
  },
};
</script>

效果图

当前页面是本站的「Google AMP」版。查看和发表评论请点击:完整版 »