Skip to content Skip to sidebar Skip to footer

How Can I Add A Tabindex Attribute To An Nvd3 Pie Chart?

I have a basic pie chart with 3 wedges. When you click on a wedge of the pie, a tooltip will display. My intent is to have the same functionality for a keydown event. Scenario: Whe

Solution 1:

So,

The function setAttribute is a vanila javascript, so it has to be used on a real javascript html element.

You have 2 options,

Solution 1

Get the javascript html element, using the function each and then getting it from this.

d3.selectAll('.nv-slice').each(function(){
    this.setAttribute("tabindex", "0");
});

Solution 2

Or as we know from jQuery (a vary polular library library) you can try to see if the equivalent function of the setAttribute exist, this function is attr.

d3.selectAll('.nv-slice').attr("tabindex", "0");

Of course all that inside the callback function.

Post a Comment for "How Can I Add A Tabindex Attribute To An Nvd3 Pie Chart?"