0
我想遍历图表中的所有数据列,并在数据列上使用onclick eventlistener。 的SVG组件通过svg组件循环d3
<g class="c3-event-rects c3-event-rects-single" style="fill-opacity: 0;">
<rect class=" c3-event-rect c3-event-rect-0" x="0" y="0" width="88" height="196"></rect>
<rect class=" c3-event-rect c3-event-rect-1" x="88" y="0" width="88" height="196"></rect>
<rect class=" c3-event-rect c3-event-rect-2" x="176" y="0" width="88" height="196"></rect>
<rect class=" c3-event-rect c3-event-rect-3" x="263" y="0" width="88" height="196"></rect>
<rect class=" c3-event-rect c3-event-rect-4" x="351" y="0" width="88" height="196"></rect></g>
所以我要通过≥C3-事件RECT-0循环到4并在这的onclick EventListener的添加。如果有人能告诉我方向,那会很有帮助。
for (k = 0; k < something.length; k++) {
dcbar = d3.selectAll("rect.c3-event-rect");
dcbar.on("click", function() {
something
});
}
您标记'angularjs'。你使用角? – inspired
你的代码是正确的,但你不需要'something'循环。它就像'd3.selectAll(“rect.c3-event-rect”)。on(“click”,function(){doSomethingAweseome()});' – Mark
是的,我使用角度js。@启发 – user2128