1. npm安装 echarts
npm install echarts --save
2. 引入Main.js中
// 引入方式如下,否则报错 import * as echarts from 'echarts' // 将 createApp(App) 封装 let app=createApp(App); // 注册全局的方法 app.config.globalProperties.$echarts = echarts;
3. 使用 echarts 第一步
给 echarts页面 准备一个宽高 <div id="myChart" :style="{ width: '1200px', height: '500px' }"></div>
4. 使用 echarts 第二步
mounted() {// 准备实例//this.$root => applet myChart = this.$root.$echarts.init(document.getElementById("myChart"));// echarts 配置// 绘制图表myChart.setOption({title: { text: "时间" },tooltip: {},xAxis: {data: ["8-21", "8-22", "8-23", "8-24", "8-25", "8-26"],},yAxis: {},series: [{name: "日期",type: "bar",data: [6, 12, 12, 18, 12, 18],},],});} }
最后echarts完成了初步的入门
参考官方文档链接: https://echarts.apache.org/