Redirect to link on label click

26 views
Skip to first unread message

pooja bhute

unread,
Nov 2, 2016, 1:04:50 AM11/2/16
to dc-js user group
Hello,

I need to make the label of the dc bubble chart as a clickable link. On click of the link the user should be redirected to a different url.

I tried creating an anchor tag in the .label of the chart but it did not work. Any ideas on how this can be done?

.label(function (p) {

 var someNumberTodisplay = p.value.count;                                     
 var aTag = document.createElement('a');
 aTag.setAttribute('href',"/someurl");
 aTag.setAttribute('title', someNumberTodisplay );

 //This did not work
 //aTag.onclick = labelClickFunction(); 

/ //This did not work either
 aTag.addEventListener("click", labelClickFunction(), false);
 return aTag;                                 
 })    


Thanks!

Gordon Woodhull

unread,
Nov 21, 2016, 2:06:58 PM11/21/16
to dc.js user group
Sorry for the slow response. There was discussion of this just a week earlier, in which I suggested using the `on('filtered', ...)` event:


Another possibility is to directly add a click event handler to the bubbles:

bubbleChart.on('pretransition', function() { // on each render or redraw...
    bubbleChart.selectAll('circle.bubble') // select all the bubbles
        .on('click.redirect', function(d) { // add a click event with your own namespace, not to interfere
            window.href = '/someurl/' + d.value; // redirect to a new url based on the data in the bubble
        });
    });
});

--
You received this message because you are subscribed to the Google Groups "dc-js user group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dc-js-user-gro...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/dc-js-user-group/a7b58151-9ea7-4834-a8b1-84db84377486%40googlegroups.com.

Reply all
Reply to author
Forward
0 new messages