marmelab/EventDrops

Unable to get the zoom object

Open

#168 建立於 2017年8月9日

在 GitHub 查看
 (3 留言) (0 反應) (0 負責人)JavaScript (249 fork)batch import
help wanted

倉庫指標

Star
 (1,219 star)
PR 合併指標
 (30 天內沒有已合併 PR)

描述

Hello everybody!

I'm currently using EventDrops in an Angular 4 application. I need to set the zoom programmatically, so I read the documentation and the example:

var eventDropsChart = d3.chart.eventDrops();
var element = d3.select('#chart_placeholder').datum(...);
eventDropsChart.call(eventDropsChart);
var zoom = element[0][0].zoom;

I have something similar in my code:

var chart = d3.chart.eventDrops()
            .date(d => d.date)
            .start(minDate)
            .end(maxDate)
            .mouseover(this.showTooltip)
            .mouseout(this.hideTooltip)
            .click(this.onEventClick)
            .zoomend(this.onZoomEnd)
            .eventLineColor((d, i) => colors[i]);

this.timeline = d3.select('#visual')
            .datum(data)
            .call(chart);

console.log("ZOOM");
console.log(this.timeline[0]); // Ouptut: undefined

but then I got undefined, so I'm unable to get the zoom.

I also tried to change the code to:

this.timeline = d3.select('#visual')
            .datum(data);

chart.call(chart);

console.log("ZOOM");
console.log(this.timeline[0]);

But then I got another error:

Cannot read property 'each' of undefined at Function.e (eventDrops.js:1)

Is it a bug or am I doing something wrong?

Thanks!

貢獻者指南