第一步先安装Echarts
npm i echarts
第二步在页面使用,进行引入相对应的配置文件
例如
// 引入基本模板
let echarts = require('echarts/lib/echarts')
require('echarts/lib/chart/pie')//饼图
// 引入提示框和title组件
require('echarts/lib/component/tooltip')
require('echarts/lib/component/title')
require('echarts/lib/component/legend')
第三步在页面内写入HTML
<div id="myChart" style="height: 230px;"></div>
第四步数据的渲染
先在methods中定义一个方法,然后mounted中进行渲染
//在mounted中使用
this.anjian_num()
//写在methods方法中
anjian_num() {
this.axios.post('/api/xx/xx.xx', {type: 'xx'}).then((res) => {
if (res.data.status == 200) {
let myChart = echarts.init(document.getElementById('myChart'), 'macarons')
var option =