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">
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值