Javascript 如何在highcharts标签中捕获悬停事件?
以以下示例为基础:Javascript 如何在highcharts标签中捕获悬停事件?,javascript,highcharts,Javascript,Highcharts,以以下示例为基础: $(函数(){ $(“#容器”)。高图({ 图表:{ 类型:“列” }, 标题:{ 文字:“2014年世界最大城市” }, 副标题:{ 文本:“来源:” }, xAxis:{ 类型:'类别', 标签:{ 轮调:-45, 风格:{ fontSize:'13px', fontFamily:“Verdana,无衬线” } } }, 亚克斯:{ 分:0,, 标题:{ 正文:“人口(百万)” } }, 图例:{ 已启用:false }, 工具提示:{ pointFormat:'200
$(函数(){
$(“#容器”)。高图({
图表:{
类型:“列”
},
标题:{
文字:“2014年世界最大城市”
},
副标题:{
文本:“来源:”
},
xAxis:{
类型:'类别',
标签:{
轮调:-45,
风格:{
fontSize:'13px',
fontFamily:“Verdana,无衬线”
}
}
},
亚克斯:{
分:0,,
标题:{
正文:“人口(百万)”
}
},
图例:{
已启用:false
},
工具提示:{
pointFormat:'2008年人口:{point.y:.1f}百万'
},
打印选项:{
系列:{
要点:{
活动:{
mouseOver:function(){alert('hello');}
}
}
}
},
系列:[{
姓名:'人口',
数据:[
[‘上海’,23.7],
['Lagos',16.1],
[Instanbul',14.2],
[‘卡拉奇’,14.0],
[‘孟买’,12.5],
[‘莫斯科’,12.1],
['São Paulo',11.8],
[Beijing',11.7],
[‘广州’,11.1],
[‘德里’,11.1],
[‘深圳’,10.5],
[首尔,10.4],
[‘雅加达’,10.0],
[“金沙萨”,9.3],
[‘天津’,9.3],
[‘东京’,9.0],
['Cairo',8.9],
[‘达卡’,8.9],
[“墨西哥城”,8.9],
[‘利马’,8.9]
],
数据标签:{
启用:对,
轮换:-90,
颜色:“#FFFFFF”,
对齐:“右”,
格式:'{point.y:.1f}',//一位小数
y:10,//从顶部向下10像素
风格:{
fontSize:'13px',
fontFamily:“Verdana,无衬线”
}
}
}]
});
});
我希望能够捕获标签中的“悬停”事件。在Highcharts API中进行了一些研究之后,我只发现如何在数据中捕获“mouseOver”事件,而不是在标签中
最终目的是在悬停标签时而不是在悬停数据时显示工具提示。您可以使用允许这样做的扩展。我的解决方法是向标签(或文本)添加鼠标悬停事件的绑定 让我们试试这个
$(function () {
$('#container').highcharts({
chart: {
type: 'column'
},
title: {
text: 'World\'s largest cities per 2014'
},
subtitle: {
text: 'Source: <a href="http://en.wikipedia.org/wiki/List_of_cities_proper_by_population">Wikipedia</a>'
},
xAxis: {
type: 'category',
labels: {
rotation: -45,
style: {
fontSize: '13px',
fontFamily: 'Verdana, sans-serif'
}
}
},
yAxis: {
min: 0,
title: {
text: 'Population (millions)'
}
},
legend: {
enabled: false
},
tooltip: {
pointFormat: 'Population in 2008: <b>{point.y:.1f} millions</b>'
},
plotOptions: {
series: {
point:{
events: {
mouseOver: function() {alert('hello');}
}
}
}
},
series: [{
name: 'Population',
data: [
['Shanghai', 23.7],
['Lagos', 16.1],
['Instanbul', 14.2],
['Karachi', 14.0],
['Mumbai', 12.5],
['Moscow', 12.1],
['São Paulo', 11.8],
['Beijing', 11.7],
['Guangzhou', 11.1],
['Delhi', 11.1],
['Shenzhen', 10.5],
['Seoul', 10.4],
['Jakarta', 10.0],
['Kinshasa', 9.3],
['Tianjin', 9.3],
['Tokyo', 9.0],
['Cairo', 8.9],
['Dhaka', 8.9],
['Mexico City', 8.9],
['Lima', 8.9]
],
dataLabels: {
enabled: true,
rotation: -90,
color: '#FFFFFF',
align: 'right',
format: '{point.y:.1f}', // one decimal
y: 10, // 10 pixels down from the top
style: {
fontSize: '13px',
fontFamily: 'Verdana, sans-serif'
}
}
}]
});
});
$('.highcharts-xaxis-labels text').bind('mouseover',function(e){
alert("You hover on "+$(this).text())
});