score:3

Accepted answer

this in callback refers to the chart itself. Buttons are stored in chart.exportSVGElements array. So, here is the solution: http://jsfiddle.net/knmb38dy/1/

                toggleButton: {
                    text: 'ON',
                    onclick: function () {
                        var button = this.exportSVGElements[0], // 0 = text element, 1 = rect button
                            $button = $(button.element); // in "element" stored is reference to the DOM object
                            text = $button.text() == "ON" ? "OFF" : "ON";

                        button.attr({
                            text: text
                        });
                    }
                }

Note using Highcharts built-in method attr() for updating text, not jQuery's text().

Edit:

For Highcharts 4.2.3+ use the solution below: http://jsfiddle.net/knmb38dy/33/

The only difference is how to get button in jQuery: $button = $(button.element.lastChild).


Related Query

More Query from same tag