![](/img/trans.png)
[英]Highcharts: how to add custom SVG icon on custom stock-tool button?
[英]How can I change icon of the custom stock-tool button on click event?
我有这个jsfiddle ,我在其中添加了两个自定义股票工具注释,其中添加了circle
和rectangle
图标以及用于toggleAnnotations
的预定义 highchart 按钮。
stockTools: {
gui: {
enabled: true,
buttons: ['oneAnnotation', 'twoAnnotation', 'toggleAnnotations'],
definitions: {
oneAnnotation: {
className: 'highcharts-one-annotation',
symbol: 'circle.svg'
},
twoAnnotation: {
className: 'highcharts-two-annotation',
symbol: 'rectangle.svg'
},
}
}
},
正如我们所看到的,在这个切换注释可见性的预定义按钮中,图标在按钮单击时发生变化。 所以我想在我的自定义按钮中拥有同样的东西。 我实际上需要一个自定义按钮(而不是上面示例中的两个),并且我想在用户单击它时更改其图标。 所以我想在circle.svg
和rectangle.svg
图标之间切换。
按钮上的点击由部件管理:
navigation: {
bindings: {
oneAnnotation: {
className: 'highcharts-one-annotation',
init: function(e) {
alert("click on the circle annotation");
}
},
twoAnnotation: {
className: 'highcharts-two-annotation',
init: function(e) {
alert("click on the rectangle annotation");
}
}
}
},
您可以切换按钮元素的backgroundImage
样式,例如:
navigation: {
bindings: {
oneAnnotation: {
className: 'highcharts-one-annotation',
init: function(button) {
var iconsURL = 'https://code.highcharts.com/8.2.2/gfx/stock-icons/';
var url1 = 'url("' + iconsURL + 'rectangle.svg' + '")';
var url2 = 'url("' + iconsURL + 'circle.svg' + '")';
var btnStyle = button.children[0].style;
btnStyle.backgroundImage = btnStyle.backgroundImage === url1 ? url2 : url1;
}
},
...
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.