Ayeshmantha Perera
Ayeshmantha Perera

Reputation: 909

Error Cannot read property 'getBoundingClientRect' of null in d3-gantt charts

Hi all when am trying to create the timeline chart I get the below error.I imported both d3 and d3-timeline

import * as d3timelines from 'd3-timelines';
import * as d3 from 'd3';
export class DashboardThreadedComponent implements OnInit {
 private data: any = [
        {label: 'person a', times: [
            {starting_time: 1355752800000, ending_time: 1355759900000},
            {starting_time: 1355767900000, ending_time: 1355774400000}]},
        {label: 'person b', times: [
            {starting_time: 1355759910000, ending_time: 1355761900000}]},
        {label: 'person c', times: [
            {starting_time: 1355761910000, ending_time: 1355763910000}]},
        ];

private chart: any;
 constructor(
        private cookieService: CookieService,
        private modalService: NgbModal,
        private bpeService: BPEService,
        private userService: UserService,
        private router: Router,
        private route: ActivatedRoute,
        public appComponent: AppComponent
  ) {}

    ngOnInit() {

        this.chart = d3timelines.timelines();

        d3.select('.timeline').append('svg').attr('width', 500)
        .datum(this.data).call(this.chart);

    }
}
}

But am getting the below error

ERROR TypeError: Cannot read property 'getBoundingClientRect' of null

Any one here that can help to fix it .Thanks alot

Upvotes: 0

Views: 3270

Answers (1)

Maayan Hope
Maayan Hope

Reputation: 1601

the timeline element probably not fully created in ngOnInit yet

To check if this is the case try:

setTimeout(() => {

        this.chart = d3timelines.timelines();

        d3.select('.timeline').append('svg').attr('width', 500)
        .datum(this.data).call(this.chart);

},1000)

Upvotes: 1

Related Questions