Giter Site home page Giter Site logo

Comments (8)

yuantingfei avatar yuantingfei commented on May 21, 2024

代码漏了
<echarts-ng2 [style]="{'width': '100%', 'height': '600px'}" #myEcharts>这里有闭合的

from ngx-echarts.

twp0217 avatar twp0217 commented on May 21, 2024

<echarts-ng2 [option]="option"></echarts-ng2>
option直接传入

from ngx-echarts.

yuantingfei avatar yuantingfei commented on May 21, 2024

但是我怎么加事件呢?

from ngx-echarts.

twp0217 avatar twp0217 commented on May 21, 2024
this.echarts.on('click', (params: Object) => {
  console.log(params);
});

https://twp0217.github.io/echarts-ng2/#/

from ngx-echarts.

yuantingfei avatar yuantingfei commented on May 21, 2024

不知道为啥 就是这样会报TypeError: _this.chart is undefined

from ngx-echarts.

yuantingfei avatar yuantingfei commented on May 21, 2024

我感觉是echarts没有初始化,但是按照例子@ViewChild('myEcharts') public echarts: ECharts;这行应该就行了呀???

from ngx-echarts.

twp0217 avatar twp0217 commented on May 21, 2024

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.

yuantingfei avatar yuantingfei commented on May 21, 2024

我知道原因了 应该在组件的生命钩子ngAfterViewInit中执行 不然会报这个错误 现在解决了 谢谢了

from ngx-echarts.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.