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>

效果图
Vue整合echarts1.png

Last modification:March 27, 2022
如果觉得这篇技术文章对你有用,请随意赞赏