心澄欲遣

不践迹,亦不入于室

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

1.安装typings及echarts

npm install typings echarts --global

2.安装 ECharts 的 TypeScript 定义文件

npm install @types/echarts --save

3.在使用echarts的页面ts文件中引用echarts

import * as echarts from 'echarts'; 

4.在html页面添加div

<ion-content> 
    <div id="chart"></div> 
</ion-content> 

5.在scss中配置样式

page-home { 
    #chart { 
        position: absolute;
        width: 100%; 
        height: 100%; 
    }
} 

6.在ts文件中初始化

ionViewDidEnter() {
    const ec = echarts as any;
    const container = document.getElementById('chart');
    const chart = ec.init(container);
    chart.setOption({
      series: {
        type: 'pie',
        data: [{
          name: 'A', value: 10
        }, {
          name: 'B', value: 20
        }, {
          name: 'C', value: 30
        }]
      }
    });
  }

 

posted on 2017-12-27 15:47  心澄欲遣  阅读(2775)  评论(0编辑  收藏  举报
欢迎第myspace graphics个访客