gpt4 book ai didi

javascript - 如何从外部调用 highcharts 按钮

转载 作者:行者123 更新时间:2023-12-03 00:36:27 27 4
gpt4 key购买 nike

我有一个简单的 highcharts,其中包含一个自定义按钮,但在这里我需要从 highcharts 中初始化该按钮,以便每当我单击它时,它不应该隐藏,只有图表应该隐藏。下面是我的代码,任何人都可以帮我吗?我已经更新了这个插件中的代码 http://plnkr.co/edit/YSLQMoQpKZqFPk0PXhXm?p=preview

HTML

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/series-label.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>
<script src="https://code.highcharts.com/modules/export-data.js"></script>
<div id="container"></div>

javascript

Highcharts.chart('container', {

title: {
text: 'Solar Employment Growth by Sector, 2010-2016'
},

subtitle: {
text: 'Source: thesolarfoundation.com'
},

yAxis: {
title: {
text: 'Number of Employees'
}
},
legend: {
layout: 'vertical',
align: 'right',
verticalAlign: 'middle'
},

plotOptions: {
series: {
label: {
connectorAllowed: false
},
pointStart: 2010
}
},

series: [{
name: 'Installation',
data: [43934, 52503, 57177, 69658, 97031, 119931, 137133, 154175]
}],

responsive: {
rules: [{
condition: {
maxWidth: 500
},
chartOptions: {
legend: {
layout: 'horizontal',
align: 'center',
verticalAlign: 'bottom'
}
}
}]
},
exporting: {
buttons: {
'myButton': {
text: 'Custom Button',
onclick: function () {
alert('You pressed the button!');
},
theme: {
class: "myButton highcharts-button highcharts-button-normal",
id: "myDiamondButton"
},
onclick: function () {
alert('You pressed the button!');
}
}
}

}

});
$("#myDiamondButton").click(function(){
$('#container').hide();
});

最佳答案

要实现这一点,请创建您希望保留在页面上的按钮作为图表范围之外的单独元素。从图表中删除“导出”选项,然后为按钮创建一个新的 HTML 元素。

Highcharts.chart('container', {

title: {
text: 'Solar Employment Growth by Sector, 2010-2016'
},

subtitle: {
text: 'Source: thesolarfoundation.com'
},

yAxis: {
title: {
text: 'Number of Employees'
}
},
legend: {
layout: 'vertical',
align: 'right',
verticalAlign: 'middle'
},

plotOptions: {
series: {
label: {
connectorAllowed: false
},
pointStart: 2010
}
},

series: [{
name: 'Installation',
data: [43934, 52503, 57177, 69658, 97031, 119931, 137133, 154175]
}],

responsive: {
rules: [{
condition: {
maxWidth: 500
},
chartOptions: {
legend: {
layout: 'horizontal',
align: 'center',
verticalAlign: 'bottom'
}
}
}]
}

});
$("#myDiamondButton").click(function(){
$('#container').hide();
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/series-label.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>
<script src="https://code.highcharts.com/modules/export-data.js"></script>

<button id="myDiamondButton" >Custom Button</button>
<div id="container"></div>
<script src="script.js"></script>

关于javascript - 如何从外部调用 highcharts 按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53638196/

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