dc lineChart pop up datapoint info on click

只愿长相守 提交于 2019-12-11 08:42:35

问题


I am attempting to detect click on line chart datapoints.

Per this answer ( dc scatter plot binding onClick event ) I am attempting to use the pretransition event as described, but I must be missing something.

lineChart.on('pretransition', function() {
    lineChart.selectAll('path.symbol').on('click', function(d) {
         alert('value: ' + d);
         //How would I pop-up the datapoint values?
    });
});

jsFiddle example


回答1:


Each chart uses different elements and classes for its diagrams. This is currently not documented, so the best bet is to go to the source.

In this case, here's the line:

var dots = g.selectAll('circle.' + DOT_CIRCLE_CLASS)

https://github.com/dc-js/dc.js/blob/f7e0a47d1246b95acbc279f14243524a0769fb84/src/line-chart.js#L279

After looking up the constant, the selector you're looking for should be circle.dot

I've added an issue to document these.

https://github.com/dc-js/dc.js/issues/1278



来源:https://stackoverflow.com/questions/42149593/dc-linechart-pop-up-datapoint-info-on-click

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!