第一步
npm install echarts --save,
npm install @types/echarts --save
下载好插件后,在你需要使用 图表的页面 ts 文件里引入
第二步
引入 图表
import * as echarts from 'echarts';
然后在 html 页面声明容器
<div class="echarts" id="chart" ></div>
非常重要:一定要在 css 页面 指定容器的高宽
.echarts{
width: 340px;
height: 200px;
margin: 0 auto
}
然后再回到 ts 页面 使用图表
che() {
const ec = echarts as any;
const container = document.getElementById('chart');
this.chart = ec.init(container);
let option = {
tooltip: {
trigger: 'axis'
},
legend: {
data: ['邮件营销', '联盟广告', '视频广告', '直接访问', &#