xAxis : [
{
triggerEvent:true,//这句很重要,没有不会触发事件
……
}
],
……
videoChart.setOption(option);
extension(videoChart);
function extension(mychart) {
//判断是否创建过div框,如果创建过就不再创建了
var id = document.getElementById("extension");
if(!id) {
var div = "<div id = ‘extension‘ style=\"display:none\"></div>" ;
$(‘html‘).append(div);
}
}
videoChart.on(‘mouseover‘, function (params) {
console.log(params);
if(params.componentType == "xAxis") {
$(‘#extension‘).css({
"position": "absolute",
"color": "black",
"font-family": "Arial",
"font-size": "14px",
"padding": "5px",
"top":"50px",
"display":"inline-block",
"z-index":"2000"
}).text(params.value);
$("html").mousemove(function(event) {
var xx = event.pageX - 30;
var yy = event.pageY + 20;
$(‘#extension‘).css(‘top‘, yy).css(‘left‘, xx);
});
}
});
videoChart.on(‘mouseout‘, function(params) {
if(params.componentType == "xAxis") {
$(‘#extension‘).css(‘display‘, ‘none‘);
}
});
原文地址:https://www.cnblogs.com/monozxy/p/9755697.html