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. 03安卓TextView

    一  TextView    父类 : View     >概念:文本控件 :文本内容的显示   默认配置不可编辑  子类EditText可以编辑 *********************** ...

  2. How To: Run Tapestry5 On JBoss 6/7

    Tapestry 5.x cannot find the core pages and components from the URLs provided from classloaders in J ...

  3. iOS中 百度地图详解 韩俊强的博文

    需要准备工作按照下图引进类库 需要添加 添加的两个字符串为:NSLocationWhenInUseUsageDescription  /  NSLocationAlwaysUsageDescripti ...

  4. 牛腩新闻发布系统--学习Web的小技巧汇总

    2014年11月10日,是个难忘的日子,这一天,小编的BS学习开始了,BS的开头,从牛腩新闻发布系统开始,之前学习的内容都是CS方面的知识,软考过后,开始学习BS,接触BS有几天的时间了,跟着牛腩老师 ...

  5. Androd选取相册照片和拍照处理-android学习之旅(62)

    实现如下图所示效果 核心代码 -构建打开相册和拍照的Intent 拍照 File outputImage = new File(Environment.getExternalStorageDirect ...

  6. 基于HTTP头部的注入

    基于HTTP头部的注入 常见的sql注入一般都是通过表单或请求参数进行注入,但这里给出的例子是通过HTTP协议头部进行注入. 例如一个的请求如下: GET / HTTP/1.1 Host: www.e ...

  7. 仿滴滴抢单倒计时的Demo

    滴滴里面有一个下单完成之后等待界面的倒计时转圈的视图... 就是这个... 原理: 通过CAShapeLayer层添加到自己自定义的视图layer上... 设置ShapeLayer的path... 他 ...

  8. 【一天一道LeetCode】#41. First Missing Positive

    一天一道LeetCode系列 (一)题目 Given an unsorted integer array, find the first missing positive integer. For e ...

  9. 【嵌入式开发】C语言 命令行参数 函数指针 gdb调试

    . 作者 : 万境绝尘 转载请注明出处 : http://blog.csdn.net/shulianghan/article/details/21551397 | http://www.hanshul ...

  10. Cocos2d中update与fixedUpdate的区别(一)

    原文链接 关于这个问题cocos2d中的fixedUpdate:(或者是Unity中的FixedUpdate)在不同论坛中出现略显频繁.它被回答过很多次了,不管如何,每次一些童鞋在得到答案后还是有一些 ...