import { Component, ElementRef, ViewChild, AfterViewInit } from '@angular/core';
@Component({ selector: 'app-chart', templateUrl: './chart.component.html', styleUrls: ['./chart.component.css'] }) export class ChartComponent implements AfterViewInit {
@ViewChild('chartContainer', { static: false }) chartContainer: ElementRef;
ngAfterViewInit() { const element = this.chartContainer.nativeElement; const width = element.offsetWidth; console.log('Chart width: ' + width); } }
import { Component, ElementRef, ViewChild, AfterViewInit } from '@angular/core'; import * as Highcharts from 'highcharts';
@Component({ selector: 'app-chart', templateUrl: './chart.component.html', styleUrls: ['./chart.component.css'] }) export class ChartComponent implements AfterViewInit {
@ViewChild('chartContainer', { static: false }) chartContainer: ElementRef;
public Highcharts = Highcharts; public chartOptions: any;
ngAfterViewInit() { const element = this.chartContainer.nativeElement; const width = element.offsetWidth;
this.chartOptions = {
chart: {
type: 'line',
width: width
},
title: {
text: 'Chart Title'
},
series: [{
data: [1, 2, 3, 4, 5]
}]
};
} }