Javascript examples for highcharts:Context Menu
Custom Context Menu Button for in Every Chart on Page
<html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <script type="text/javascript" src="https://code.jquery.com/jquery-1.9.1.js"></script> <script type="text/javascript"> $(window).load(function(){// w ww . j ava2 s . co m function appendExportButton(mytext, myfunction){ var defaultButtons = Highcharts.getOptions().exporting.buttons; // get default Highchart Export buttons var myButtons = $.extend(true, {}, defaultButtons); myButtons.contextButton.menuItems.push({ text: mytext, onclick: myfunction }); return {buttons: myButtons}; } var chartTokyo = new Highcharts.Chart({ chart: { renderTo: 'containerTokyo' }, title: { text: 'Tokyo Average Temperature', x: -20 //center }, xAxis: { categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'] }, series: [ { name: 'Tokyo', data: [7.0, 6.9, 9.5, 14.5, 18.2, 21.5, 25.2, 26.5, 23.3, 18.3, 13.9, 9.6] }], exporting: appendExportButton("Tokyo Only Option", HelloWorld) }); var chartNewYork = new Highcharts.Chart({ chart: { renderTo: 'containerNewYork' }, title: { text: 'New York Average Temperature', x: -20 //center }, xAxis: { categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'] }, series: [ { name: 'New York', data: [-0.2, 0.8, 5.7, 11.3, 17.0, 22.0, 24.8, 24.1, 20.1, 14.1, 8.6, 2.5] }] }); function HelloWorld(){ console.log("Hello World"); } }); </script> </head> <body> <script src="https://rawgithub.com/highslide-software/highcharts.com/master/js/adapters/standalone-framework.src.js"></script> <script src="https://code.highcharts.com/highcharts.js"></script> <script src="https://code.highcharts.com/modules/exporting.js"></script> <script src="https://code.highcharts.com/modules/drilldown.js"></script> <p>The Custom menu option 'Tokyo Only Option' should only appear in the Tokyo chart, but it appears in both.</p> <div id="containerTokyo" style="min-width: 300px; height: 300px; margin: 1em"></div> <div id="containerNewYork" style="min-width: 300px; height: 300px; margin: 1em"></div> </body> </html>