import {Component, Input, AfterViewInit} from '@angular/core';
import {ViewChild, ElementRef} from '@angular/core';
import * as echarts from "echarts"

@Component({
  selector: 'app-comp-echarts',
  templateUrl: './comp-echarts.component.html',
  styleUrls: ['./comp-echarts.component.scss']
})
export class CompEchartsComponent implements AfterViewInit {
  @Input() options: any
  @ViewChild("chartDiv") chartDiv: ElementRef = new ElementRef(undefined);

  constructor() {
  }

  ngAfterViewInit(): void {
    this.createEcharts();
  }

  async createEcharts() {
    let chartDom = this.chartDiv.nativeElement;
    let myChart = echarts.init(chartDom);
    this.options && myChart.setOption(this.options);
  }

}
