问题
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