d3.scale.category20 is too smart for me

Can anybody explain to me why these two expressions return different values… … in the following context Working example… Expand snippet The user agent reported in my system is Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.85 Safari/537.36 I kind of get the above behaviour but this is very strange… Why is this… … Read more

How to add a tooltip to an svg graphic?

You can use the title element as Phrogz indicated. There are also some good tooltips like jQuery’s Tipsy http://onehackoranother.com/projects/jquery/tipsy/ (which can be used to replace all title elements), Bob Monteverde’s nvd3 or even the Twitter’s tooltip from their Bootstrap http://twitter.github.com/bootstrap/

D3 Appending Text to a SVG Rectangle

A rect can’t contain a text element. Instead transform a g element with the location of text and rectangle, then append both the rectangle and the text to it: http://bl.ocks.org/mbostock/7341714 Multi-line labels are also a little tricky, you might want to check out this wrap function.

Attaching ‘onclick’ event to D3 chart background

The event isn’t actually overridden, but both are triggered — the onclick handler for the SVG and for the bar. To prevent this, use the .stopPropagation() method (see the documentation). The code looks like this: Complete example here. Compare with the behaviour with stopping the propagation of the event here.