ng2 中使用echart
1.首先创建echarts指令
//echart.directive.ts
important { Directive,ElementRef,Input,Ouput,Onchanges,OnInit,OnDestroy,SimpleChanges,EventEmitter} from '@angular/core';
important * as echarts from 'echarts'; @Directive({
selector: 'echart'
}) export class EchartOptiononDirective implements OnInin,OnChanges,OnDestroy {
@Input('chartType') chartType:any;
@Output() resizeEle = new EventEmitter<any>();
public Ele;
constructor(private el:ElementRef){} ngOnInit():void {}
ngOnChanges(changes:SimpleChanges) {
let params;
if(params != this.chartType){
params = this.chartType;
if(this.Ele){this.Ele.dispose()} //每次change改变echart实例,防止内存泄漏
this.Ele = echarts.init(this.el.nativeElement); //绘制图表
this.Ele.setOption(this.chartType);
this.resizeEle.emit(this.Ele); //resize图表
}
}
ngOnDestroy(){
if(this.Ele){this.Ele.dispose()}
}
}
2.组件模板中引入指令
//echart.module.ts
import {EchartOptionDirective} from './echart.directive' @NgModule({
declarations:[
EchartOptionDirective
]
})
3.组件中使用echart
//echart.component.ts
export class EchartComponent implements OnInit,OnDestroy{
public chartoption:any;
public echart:any;
constructor(){
window.onresize = () => { //改变窗口大小reseze图表
this.echart.resize();
}
}
ngOnInit(){
window.onresize = () => {
this.echart.resize();
}
}
ngOnDestroy() {
window.onresize = () => {}; //防止内存泄漏
}
resizeElement(e){
this.echart= e;
}
renderChart(){
this.chartoption = {
//此处为echart图表相关内容
backgtoundColor:'#fff',
title:{},
...
}
}
}
4.html中使用echart
//echart.component.html
<echart *ngIf = "chartoption" [chartType] = "chartoption" (resizeEle) = "resizeElement($event)"></echart>
ng2 中使用echart的更多相关文章
- ng2 中的全屏与退出全屏
1.进入全屏 launchFullscreen(element) { if(element.requestFullscreen) { element.requestFullscreen(); } el ...
- Django框架中使用Echart进行统计的SQL语句
最近想用Echart做数据统计的图形显示,数据来源是MySQL数据库,自然需要根据不同的搜索条件筛选出表中的数据,用比较多的就是时间的参数吧! 常用的mysql时间的条件进行检索的SQL语句: 数据表 ...
- 网站中使用echart
在网站开发中,可能会使用折线图,圆饼图,等等 来丰富网页对数据的展示,可以使用echart http://echarts.baidu.com/tutorial.html#5%20%E5%88%86%E ...
- angular中使用echart遇到的获取容器高度异常的问题记录
问题 在使用echart去创建图表时,发现图表只占了容器的一个角落,如图,并没有充满容器. 第一反应是容器元素的样式有问题,于是我把容器的宽高都改为px指定的(之前是百分比设定的,查询资料发现说ech ...
- vuejs中使用echart图表
首先安装echart npm i echarts -S 加下来以使用这个图表为例 在vue组件中像这样使用: <template> <div :class="classNa ...
- 切换tab页时,tab页中的echart变形问题
本文为博主原创,未经允许,不得转载: 在两个tab页中,分别展现了两个echart图表,同样的格式与写法,但只有在默认选中的tab页中的图表显示的是正常的, 但进入另一个tab页中时,图表则产生了变形 ...
- angular5中使用echart的方法
注意两点安装的版本 安装好后可以参照echart的官网使用 1.实现package.json中安装这两个包 2.index.html中引入 3.在appModule中添加 然后再html中就可以这么使 ...
- 如何在vue中使用echart
1.安装echarts依赖 npm install echarts --save 2.在main.js中全局中引用 import echarts from 'echarts' Vue.protot ...
- 在Vue中使用Echart图表库。【全网最简单】
使用npm安装echart npm install echarts --save 然后在使用的页面上直接import import echarts from "echarts"; ...
随机推荐
- Django自定义对象转成json字符串
1.定义转换函数:def convert_to_builtin_type(obj): print 'default(', repr(obj), ')' # 把MyObj对象转换成dict类型的对象 d ...
- 转。git 乌龟的使用安装
TortoiseGit 简称 tgit, 中文名海龟Git. 海龟Git只支持神器 Windows 系统, 有一个前辈海龟SVN, TortoiseSVN和TortoiseGit都是非常优秀的开源的版 ...
- Write 语句
ABAP Write 语句 转载▼http://blog.sina.com.cn/s/blog_5ccd375b0100ghhi.html 1.Write 叙述 ABAP/4 用来在屏幕上输出数据 ...
- JVM调优-工具篇
原文地址 16年的时候花了一些时间整理了一些关于jvm的介绍文章,到现在回顾起来还是一些还没有补充全面,其中就包括如何利用工具来监控调优前后的性能变化.工具做为图形化界面来展示更能直观的发现问题,另一 ...
- fedora25 安装sublime text3
fedora 25安装使用 sublime text 3 安装 sublime text 3 fedora 需要选择 tarball 版本.下载后将 sublime text 3 解压后放到 opt ...
- Python基础(2)_数字和字符串类型
一.数据类型 1.数字 整型 Python的整型相当于C中的long型,Python中的整数可以用十进制,八进制,十六进制表示. >>> --------->默认十进制 > ...
- ubuntu13.04中把ibus中的中文拼音输入设为默认
全新的ubuntu ,先选择 下载服务器 首选项->软件和更新 选择 最佳服务器 准备工作:卸载Ubuntu默认的ibus输入法: sudo apt-get remove ibus 然后添加Fc ...
- nodejs之入门
一.安装: 去官网下载稳定版本,安装即可. 安装后执行node -v,显示node版本,然后输入node回车,然后输出console.log(111);,正常输出即可. 二.入门介绍: 1.nodej ...
- 【Flask】视图高级
# 视图高级笔记:### `add_url_rule(rule,endpoint=None,view_func=None)`这个方法用来添加url与视图函数的映射.如果没有填写`endpoint`,那 ...
- shell文件相关指令
文件解压缩tar 请参考文档:http://blog.csdn.net/eroswang/article/details/5555415/ tar -zcvf ${standardpath}${fil ...