JavaScript and jQuery for Data Analysis and Visualization by Jon Raasch & Graham Murray & Vadim Ogievetsky & Joseph W. Lowery

JavaScript and jQuery for Data Analysis and Visualization by Jon Raasch & Graham Murray & Vadim Ogievetsky & Joseph W. Lowery

Author:Jon Raasch & Graham Murray & Vadim Ogievetsky & Joseph W. Lowery
Language: eng
Format: epub
ISBN: 9781118847220
Publisher: Wiley
Published: 2014-11-24T00:00:00+00:00


Adding Mouse Interactivity

Now that the script renders the chart, the next step is to add interactivity. Fortunately, setting up a click handler is pretty easy with the SVG event listeners. First, create an option the developer can use for click handlers:

o.onclick = o.onclick || function() {};

and then apply the handler in the build_segment() function:

function build_segment(j) { var value = values[j], angleplus = 360 * value / total, styleOpts = { fill: o.colors[j] }; if ( o.strokeWidth ) { styleOpts.stroke = o.strokeColor; styleOpts['stroke-width'] = o.strokeWidth; } else { styleOpts.stroke = 'none'; } var arc = draw_arc( angle, angle + angleplus, styleOpts ); arc.click( function() { o.onclick(j); }); angle += angleplus; }



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.