Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error Cannot read property 'getBoundingClientRect' of null. #22

Open
Akayeshmantha opened this issue May 24, 2019 · 1 comment
Open

Comments

@Akayeshmantha
Copy link

Akayeshmantha commented May 24, 2019

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

@rijvirajib
Copy link

This is usually because the DOM isn't really ready.
Wrapping the d3.select in a setTimeout will resolve it. On a large app of mine, I've had to set the timeout to 100 to guarantee the SVG is ready.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants