在角+组分收到HighStock RangeSelector按钮事件(Recieve HighSto

2019-10-28 21:13发布

我想现在用的是访问我的角度component.I内highstock rangeSelector按钮事件angular2-highcharts包使用highcharts库。 尝试使用访问它(afterSetExtremes)结合,但没有成功。 该代码是在这里 。 请帮忙。

谢谢!!

Answer 1:

更新您的模板

template: `
  <chart type="StockChart" [options]="options" (click)="onClick($event)">
  </chart>
`,

功能

onClick(e) {
  console.log('You clicked '+e.toElement.innerHTML+" button")
}

Plunker演示



Answer 2:

检查打字稿 highcharts版本安装及以下执行。

stackblitz演示

import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { NgModule, ViewChild, ElementRef } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { Component } from '@angular/core';
import * as Highcharts from 'highcharts/highstock';
import { Jsonp, JsonpModule } from '@angular/http';

@Component({
  selector: 'my-app',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css'],

})
export class AppComponent {
  name = 'Angular 5 Highstock';
  @ViewChild("container", { read: ElementRef }) container: ElementRef;

  constructor(jsonp: Jsonp) {
    jsonp.request('https://www.highcharts.com/samples/data/jsonp.php?filename=aapl-c.json&callback=JSONP_CALLBACK').subscribe(res => {


      Highcharts.stockChart(this.container.nativeElement, {
        rangeSelector: {
          buttons: [{
            type: 'month',
            count: 1,
            text: '1m',
            events: {
              click: function (e) {
                console.log('button clickd');
              }
            }
          }, {
            type: 'month',
            count: 3,
            text: '3m'
          }, {
            type: 'month',
            count: 6,
            text: '6m'
          }, {
            type: 'ytd',
            text: 'YTD'
          }, {
            type: 'year',
            count: 1,
            text: '1y'
          }, {
            type: 'all',
            text: 'All1'
          }]
        },
        chart: {
          zoomType: 'x'
        },
        series: [{
          name: 'AAPL',
          data: res.json(),
          tooltip: {
            valueDecimals: 2
          }
        }],
        xAxis: {
          events: {
            afterSetExtremes: (e) => {
              // console.log(e);
              // this.button = e.rangeSelectorButton.count;

            }
          }
        },
      })
    })
  }
}


文章来源: Recieve HighStock RangeSelector button event in Angular 2+ component