Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/413.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 错误:无法读取属性';getBoundingClientRect';d3甘特图中的空值_Javascript_Angular_D3.js_Angular6 - Fatal编程技术网

Javascript 错误:无法读取属性';getBoundingClientRect';d3甘特图中的空值

Javascript 错误:无法读取属性';getBoundingClientRect';d3甘特图中的空值,javascript,angular,d3.js,angular6,Javascript,Angular,D3.js,Angular6,大家好,当我尝试创建时间线图表时,我得到以下错误。我同时导入了d3和d3时间线 import * as d3timelines from 'd3-timelines'; import * as d3 from 'd3'; export class DashboardThreadedComponent implements OnInit { private data: any = [ {label: 'person a', times: [ {starti

大家好,当我尝试创建时间线图表时,我得到以下错误。我同时导入了d3和d3时间线

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);

    }
}
}
但是我得到了下面的错误

ERROR TypeError: Cannot read property 'getBoundingClientRect' of null

这里的任何人都可以帮助修复它。非常感谢,时间线元素可能还没有在ngOnInit中完全创建

要检查是否存在这种情况,请尝试:

setTimeout(() => {

        this.chart = d3timelines.timelines();

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

},1000)