命令安裝:npm install echarts --save
在index.html的<head></head>標簽中引入echarts
<script src="https://cdn.staticfile.org/echarts/4.3.0/echarts.min.js"></script>
或者是在官網直接下載echarts.min.js文件在引入
在項目的入口文件man.js中
import echarts from
"echarts"
在需要用到的頁面中創建實例
<div id="myChart" ref="myChart" style="width: 600px;height:400px;"></div>
var echarts = require('echarts');
var myChart = echarts.init(document.getElementById('myChart'));
// 指定圖表的配置項和數據
var option = {
title: {
text: '示例'
},
tooltip: {},
legend: {
data:['銷量']
},
xAxis: {
data: ["襯衫","羊毛衫","雪紡衫","褲子","高跟鞋","襪子"]
},
yAxis: {},
series: [{
name: '銷量',
type: 'bar',
data: [5, 20, 36, 10, 10, 20]
}]
};
// 使用剛指定的配置項和數據顯示圖表。
myChart.setOption(option);