ionic3使用echart插件

安装

看官方文档能够知道ECharts能够在webpack中使用看这里,故咱们可使用npm下载安装到项目中html

npm install echarts --save //下载ECharts 
npm install @types/echarts --save // ECharts的官方版本是基于JavaScript 的,下载ECharts的TypeScript定义文件

 

使用

1.在页面建立一个echart容器webpack

<div #main1 id="main1" style="width: 100%;height: 280px"></div>
//或者
<div id="main1" style="width: 100%;height: 280px"></div>

2.在须要使用的页面的ts文件中引入echart并初始化web

import ECharts from 'echarts'; 或 import * as ECharts from "echarts";
  • 使用传统的dom操做
let myChart = ECharts.init(document.getElementById('main2') as HTMLDivElement);
  • 使用@ViewChild,建议使用此angular的dom操做
@ViewChild('main1') mychart1: ElementRef; let myChart = ECharts.init(this.mychart1.nativeElement);

完整代码:npm

let myChart = ECharts.init(document.getElementById('main2') as HTMLDivElement); option = { xAxis: { type: 'category', data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'] }, yAxis: { type: 'value' }, series: [{ data: [820, 932, 901, 934, 1290, 1330, 1320], type: 'line' }] }; myChart.setOption(option );

 

 

 

 

参考:echarts

ionic2 引入百度ECharts3dom