gpt4 book ai didi

highcharts - 使用 highcharts 切换自定义按钮文本

转载 作者:行者123 更新时间:2023-12-01 14:24:05 25 4
gpt4 key购买 nike

有什么方法可以切换 highcharts 中的自定义按钮文本吗?

toggleButton: {
text: 'ON',
onclick: function () {
console.log($(this).text());
$(this).text(function (i, text) {
return text === "ON" ? "OFF" : "ON";
});
}
}

Demo Link

最佳答案

回调中的

this 指的是图表本身。按钮存储在 chart.exportSVGElements 数组中。所以,这里是解决方案: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
});
}
}

请注意使用 Highcharts 内置方法 attr() 来更新文本,而不是 jQuery 的 text()

编辑:

对于 Highcharts 4.2.3+ 使用以下解决方案:http://jsfiddle.net/knmb38dy/33/

唯一的区别是如何在 jQuery 中获取按钮:$button = $(button.element.lastChild)

关于highcharts - 使用 highcharts 切换自定义按钮文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28169285/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com