score:12

Accepted answer

to add button use options for chart. then you can set for each chart different set of options: http://jsfiddle.net/4up5y/4/

get default buttons:

var buttons = highcharts.getoptions().exporting.buttons.contextbutton.menuitems;

buttons.push({
    text: "tokyo only option",
    onclick: helloworld
});

and set them for a chart:

exporting: {
    buttons: {
        contextbutton: {
            menuitems: buttons // or buttons.slice(0,6)
        }
    }
},

score:0

i found another possiblity to add it only to one chart. add following to the chart where you want to extend the context menu

       exporting: {
            buttons: {
                contextbutton: {
                    menuitems: [

                    ]
                }
            }
        },

. now you are able to extend the chart dynamicly with a method like

 function (button) {
    var usermenu = this.chart.useroptions.exporting.buttons.contextbutton.menuitems;
    if (usermenu.length === 0) {
        var menuitems = highcharts.getoptions().exporting.buttons.contextbutton.menuitems;
        for (var itemindex in menuitems) {
            usermenu.push(menuitems[itemindex]);
        }
    }
    usermenu.push(button);
};

. where this.chart points to the chart which context menu should be extended

score:1

see the updated fiddle with result : http://jsfiddle.net/4up5y/3/

you just needed to mark the newyork chart with exporting enabled false, like this :

    exporting: {
        enabled: false
    }

score:1

starting from paweł fus answer, i found out a cleaner solution for the general case. the main issue is you need not to mess around with original object and extend it. instead, you'd be better cloning it. please note that my solution requires jquery.

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};
}

to insert this button in the desired chart, define the chart this way:

var mychart = new highcharts.chart({
  chart: {
    ...whatever...
  },
  plotoptions: {
    ...whatever...
  },
  series: {
    ...whatever...
  },
  exporting: appendexportbutton("save data in csv format", savecsv)
});

in the case of op problem, this is the line you have to use:

exporting: appendexportbutton("tokyo only option", helloworld)

jsfiddle


Related Query

More Query from same tag