Search code examples
javascripttime-seriestooltiplegendrickshaw

How can I implement tooltips for Rickshaw legends?


I'm using Rickshaw to display a graph of several time series with a legend. I would like to display some text when the user hovers the mouse cursor over an entry in the legend. There is apparently no built-in way to do this in Rickshaw. I assume I can iterate over what the Rickshaw.Graph.Legend() constructor returns and add title attributes, but the details elude me.


Solution

  • I figured it out on my own. Here are the essentials, without error checking, etc.:

    var legend = new Rickshaw.Graph.Legend( {
        graph: _graph,
        element: document.getElementById('legend')
    } );
    
    var nodes = legend.element.firstChild.getElementsByTagName('li');
    for (var li in nodes)
        nodes[li].getElementsByTagName('span')[0].title = "I'm a tooltip!".