Comments (8)
代码漏了
<echarts-ng2 [style]="{'width': '100%', 'height': '600px'}" #myEcharts>这里有闭合的
from ngx-echarts.
<echarts-ng2 [option]="option"></echarts-ng2>
option直接传入
from ngx-echarts.
但是我怎么加事件呢?
from ngx-echarts.
this.echarts.on('click', (params: Object) => {
console.log(params);
});
https://twp0217.github.io/echarts-ng2/#/
from ngx-echarts.
不知道为啥 就是这样会报TypeError: _this.chart is undefined
from ngx-echarts.
我感觉是echarts没有初始化,但是按照例子@ViewChild('myEcharts') public echarts: ECharts;这行应该就行了呀???
from ngx-echarts.
html
<echarts-ng2 #echarts [option]="option"></echarts-ng2>
<div class="row">
<div class="col-md-12">
<a class="btn btn-primary" (click)="onEvent()">绑定点击事件</a>
<a class="btn btn-primary" (click)="offEvent()">解除点击事件</a>
</div>
</div>
ts
import { Component, ViewChild } from '@angular/core';
import { EChartOption, ECharts } from 'echarts-ng2';
@Component({
selector: 'method-charts',
templateUrl: 'method.component.html'
})
export class MethodComponent {
@ViewChild('echarts') echarts: ECharts;
option: EChartOption = {
title: {
text: 'ECharts 入门示例'
},
tooltip: {},
legend: {
data: ['销量']
},
xAxis: {
data: ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"]
},
yAxis: {},
series: [{
name: '销量',
type: 'bar',
data: [5, 20, 36, 10, 10, 20]
}]
};
onEvent() {
this.echarts.on('click', (params: Object) => {
console.log(params);
});
}
offEvent() {
this.echarts.off('click');
}
}
按照这个试试
from ngx-echarts.
我知道原因了 应该在组件的生命钩子ngAfterViewInit中执行 不然会报这个错误 现在解决了 谢谢了
from ngx-echarts.
Related Issues (20)
- hello, what version of your echart? HOT 1
- flex布局eCharts初始化显示不正常 HOT 5
- ng lint error
- node_modules/echarts-ng2/src/component/echarts-ng2.component.ngfactory.ts is not part of the compilation. Please make sure it is in your tsconfig via the 'files' or 'include' property. HOT 2
- 如何使用Echarts 全局对象? HOT 9
- how to use dataZoom events of echats ? HOT 1
- use with Angular5 HOT 2
- echart4.0? HOT 2
- angular5 报错 HOT 4
- 如果能给pc端提供一个根据容器自适应的开关就好了 HOT 3
- echarts-ng2中地图的使用问题
- 如何使用bmap HOT 8
- 如何获得全局 echarts 对象 HOT 1
- update to 5.0.0 error found version 4, expected 3 HOT 4
- showLoading样式无效 HOT 2
- Ionic4 是否无法使用? HOT 2
- Cannot read property 'resize' of null or other property HOT 8
- 请问支持angular8吗? HOT 1
- Support Angular 13
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ngx-echarts.