https://stackoverflow.com/questions/38158318/is-it-possible-to-use-echarts-baidu-with-angular-2-and-typescript

npm install --save echarts
npm install --save-dev @types/echarts

code

import {
Directive, ElementRef, Input, OnInit, HostBinding, OnChanges, OnDestroy
} from '@angular/core'; import {Subject, Subscription} from "rxjs"; import * as echarts from 'echarts';
import ECharts = echarts.ECharts;
import EChartOption = echarts.EChartOption; @Directive({
selector: '[ts-chart]',
})
export class echartsDirective implements OnChanges,OnInit,OnDestroy {
private chart: ECharts;
private sizeCheckInterval = null;
private reSize$ = new Subject<string>();
private onResize: Subscription; @Input('ts-chart') options: EChartOption; @HostBinding('style.height.px')
elHeight: number; constructor(private el: ElementRef) {
this.chart = echarts.init(this.el.nativeElement, 'vintage');
} ngOnChanges(changes) {
if (this.options) {
this.chart.setOption(this.options);
}
} ngOnInit() {
this.sizeCheckInterval = setInterval(() => {
this.reSize$.next(`${this.el.nativeElement.offsetWidth}:${this.el.nativeElement.offsetHeight}`)
}, 100);
this.onResize = this.reSize$
.distinctUntilChanged()
.subscribe((_) => this.chart.resize()); this.elHeight = this.el.nativeElement.offsetHeight;
if (this.elHeight < 300) {
this.elHeight = 300;
}
} ngOnDestroy() {
if (this.sizeCheckInterval) {
clearInterval(this.sizeCheckInterval);
}
this.reSize$.complete();
if (this.onResize) {
this.onResize.unsubscribe();
}
}
}

use ECharts with Angular 2 and TypeScript的更多相关文章

  1. Angular 个人深究(一)【Angular中的Typescript 装饰器】

    Angular 个人深究[Angular中的Typescript 装饰器] 最近进入一个新的前端项目,为了能够更好地了解Angular框架,想到要研究底层代码. 注:本人前端小白一枚,文章旨在记录自己 ...

  2. Angular:了解Typescript

    Angular是用Typescript构建的.因此在学习Angular之前有必要了解一下Typescript. [ 类型 ] Typescript增加了类型系统,好处是: 1. 有助于代码编写,预防在 ...

  3. [转]VS Code 扩展 Angular 6 Snippets - TypeScript, Html, Angular Material, ngRx, RxJS & Flex Layout

    本文转自:https://marketplace.visualstudio.com/items?itemName=Mikael.Angular-BeastCode VSCode Angular Typ ...

  4. Angular基础(三) TypeScript

    一.模仿Reddit a) 运行ng new –ng4angular-reddit创建应用,从随书代码中复制样式文件,新建组件app-root,代码为: 界面可以看到了: b) 对于界面输入的数据,获 ...

  5. [开源]eCharts配置简化包OptionCreator[typescript版]

    eCharts存在问题 配置eCharts的option,对于大部分的开发者来说,复杂情况下是一件繁琐的事情.为什么繁琐,大致有以下这些原因 大小写敏感:在没有IDE的智能提示下,很容易写错,而且即使 ...

  6. [开源][示例更新]eCharts配置简化包OptionCreator[typescript版]

    前言 eCharts作为国内优秀的开源图表工具,功能强大,但是使用中也存在一定的问题. 文档更新较慢,文档说明不详细. 前端使用的弱类型语言,数据结构在灵活的同时,也容易造成一些问题.例如某些属性到底 ...

  7. angular 2 - 003 typescript

    http://www.typescriptlang.org/docs/index.html var book: string = "hellp angular 2"; var nu ...

  8. Angular使用echarts

    安装 npm install echarts --save npm install @types/echarts --save 基本使用 定义一个dom <div id="chart& ...

  9. 翻译:Angular 2 - TypeScript 5 分钟快速入门

    原文地址:https://angular.io/docs/ts/latest/quickstart.html Angular 2 终于发布了 beta 版.这意味着正式版应该很快就要发布了. 让我们使 ...

随机推荐

  1. 部署Openfire3.9.3源码部署

    1,下载Openfire3.9.3源码代码:http://www.igniterealtime.org/downloads/index.jsp 2,具体的配置请参考http://blog.csdn.n ...

  2. java 判断是否是周末

    package untitled7; import java.util.Date; import java.text.SimpleDateFormat; import java.util.Calend ...

  3. 用SpriteBuilder简化"耕牛遍地走"的动画效果(四)

    写到这突然有童鞋质疑,你这哪里是牛,分明是熊嘛! 仔细看了下,还真像牛.反正是这个意思.怪本猫猪牛熊不分,好在道理是一样的. 下面继续,言归正传. 添加一个空白的touchBegan方法,如果没有这个 ...

  4. Docker教程:镜像构建和自动镜像构建dockerfile

    http://blog.csdn.net/pipisorry/article/details/50805379 Docker透过Dockerfile来记录建立Container映象文件的每一个步骤,可 ...

  5. Android的资源类型和存储方式简介-android学习之旅(五十二)

    android资源的类型 android资源的存储方式

  6. 【unix网络编程第三版】阅读笔记(三):基本套接字编程

    unp第三章主要介绍了基本套接字编程函数.主要有:socket(),bind(),connect(),accept(),listen()等. 本博文也直接进入正题,对这几个函数进行剖析和讲解. 1. ...

  7. 【一天一道LeetCode】#117. Populating Next Right Pointers in Each Node II

    一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 Follow ...

  8. Android学习之Animation(一)

    3.0以前,android支持两种动画模式,Tween Animation,Frame Animation,在android3.0中又引入了一个新的动画系统:Property Animation,这三 ...

  9. 【一天一道LeetCode】#86. Partition List

    一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 Given a ...

  10. python类定义

    在我的收藏中有一篇特别详细的类讲解 此处部分内容引自:http://blog.sina.com.cn/s/blog_59b6af690101bfem.html class myclass: 'this ...