Highcharts的events(1)
Clicked(鼠标点击事件)
var chart = Highcharts.chart('container',{
chart: {
plotBackgroundColor: null,
plotBorderWidth: null,
plotShadow: false
},
title: {
text: '统计信息'
},
tooltip: {
},
plotOptions: {
series:{
events:{
click:function(e){
console.log(e)
alert(e.point.name);
}
}},
pie: {
allowPointSelect: true,
cursor: 'pointer',
dataLabels: {
enabled: true,
style: {
color: (Highcharts.theme && Highcharts.theme.contrastTextColor) || 'black'
}
},
showInLegend: true
}
},
series: [
{
type: 'pie',
name: '次数',
data: [{y:1,name:'test1'},{y:2,name:'test2'}]
}]
});
在plotOptions的events中对series进行相关事件进行配置。
series的点击事件,默认的方法是click,相较于一般的控件,是默认series的点击事件方法名为cl
ick,无固定的返回值。相较而言,remmove等事件,需要在其他地方调用,且内部方法固定。remove
方法的默认返回值为true,直接调用remove函数可以删除当前节点。
click:function(e){
//console.log(e);
if (confirm('Do you really want to remove this point?')) {
console.log(1);
//alert(e.point.name);
e.point.remove();
}else{
console.log(2);
}
}
可以参考:
width="100%" height="450" src="https://code.hcharts.cn/temp/JJdjx2/5/share/result,js,html,css" allowfullscreen="allowfullscreen">被外部控件调用的highcharts内置方法
在这里以remove方法为例子。
javascript
var chart = Highcharts.chart('container', {
plotOptions: {
series: {
point: {
events: {
remove: function () {
if (!confirm('Do you really want to remove the first point?')) {
return false;
}
}
}
}
}
},
series: [{
data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4]
}]
});
$('#button').click(function () {
var series = chart.series[0];
if (series.data.length) {
chart.series[0].data[0].remove();
}
});
html
<div id="container" style="min-width:400px;height:400px"></div>
<input id="button" type="button" value="button">
可以参考:
width="100%" height="450" src="https://code.hcharts.cn/temp/JJdjx2/3/share/result,js,html,css" allowfullscreen="allowfullscreen">