Javascript 如何使工具提示平滑地跟随鼠标?

Javascript 如何使工具提示平滑地跟随鼠标?,javascript,charts,google-visualization,linegraph,Javascript,Charts,Google Visualization,Linegraph,我想知道是否有可能使工具提示在鼠标悬停在另一个坐标上时跟随鼠标,以延迟但平滑的过渡?此时工具提示出现并立即消失。我想知道是否可以用一种简单的方法来做 google.charts.load('current', { callback: function () { var rawData = [ [2010, 100, 100], [2011, 105, 120], [2012, 111, 122], [2013, 122, 132], [2014,

我想知道是否有可能使工具提示在鼠标悬停在另一个坐标上时跟随鼠标,以延迟但平滑的过渡?此时工具提示出现并立即消失。我想知道是否可以用一种简单的方法来做

    google.charts.load('current', {
callback: function () {
var rawData = [
    [2010, 100, 100],
    [2011, 105, 120],
    [2012, 111, 122],
    [2013, 122, 132],
    [2014, 131, 146],
    [2015, 139, 150],
    [2016, 143, 156],
];


var data = new google.visualization.DataTable({
  "cols": [
    {"id":"","label":"Date","type":'number'},
    {"id":"","label":"Black","type":'number'},
    {"id":"","label":"White","type":"number"}
  ]
});   

var options = {
    backgroundColor: 'transparent',
    focusTarget: 'category',
    lineWidth: 3,
    colors: ['#000'],
    crosshair: { orientation: 'vertical', trigger: 'both', color: 'black' },
    tooltip: { isHtml: true},
    pointSize: 0,
    animation:{
    startup: true,
    duration: 300,
    easing: 'out'
  },
    legend: 'none',
    series: {
        0: { lineDashStyle: [4, 4],tooltip : false, color:'rgb(223, 119, 106)', enableInteractivity: false, format: '0000'},
        1: {color:'black', zIndex:5, format: '0000'},
    },
    hAxis: {
      format: '0000',
      gridlines: { color: 'transparent', count: 6 },
      textStyle: { fontSize: 14, color: 'black' },
      viewWindow: { min: 2010, max: 2016 }
  },
    vAxis:{ 
      gridlines: { count: 7 },
        textPosition: 'none',
      textStyle: { color: 'transparent' },
      viewWindow: { min: 100, max: 160 }
  },
    chartArea: { top: 110, left: 20, right: 200 },
};

var chart = new google.visualization.LineChart(document.getElementById('chart_div'));


drawChart();
setInterval(drawChart, 500);


var rowIndex = 0;
function drawChart() {
  if (rowIndex < rawData.length) {
    data.addRow(rawData[rowIndex++]);
    chart.draw(data, options);
  }
}
},
packages:['corechart']
});
google.charts.load('current'{
回调:函数(){
var rawData=[
[2010, 100, 100],
[2011, 105, 120],
[2012, 111, 122],
[2013, 122, 132],
[2014, 131, 146],
[2015, 139, 150],
[2016, 143, 156],
];
var data=new google.visualization.DataTable({
“科尔斯”:[
{“id”:“”“标签”:“日期”,“类型”:“编号”},
{“id”:“”“label”:“Black”,“type”:“number”},
{“id”:“”“标签”:“白色”,“类型”:“编号”}
]
});   
变量选项={
背景色:“透明”,
焦点目标:“类别”,
线宽:3,
颜色:['#000'],
十字线:{方向:'vertical',触发器:'both',颜色:'black'},
工具提示:{isHtml:true},
点大小:0,
动画:{
是的,
持续时间:300,
放松:“退出”
},
图例:“无”,
系列:{
0:{lineDashStyle:[4,4],工具提示:false,颜色:'rgb(223,119,106)',enableInteractivity:false,格式:'0000',
1:{color:'black',zIndex:5,格式:'0000'},
},
哈克斯:{
格式:'0000',
网格线:{color:'透明',计数:6},
textStyle:{fontSize:14,颜色:'black'},
视图窗口:{最小值:2010,最大值:2016}
},
动词:{
网格线:{count:7},
text位置:“无”,
textStyle:{color:'transparent'},
视图窗口:{最小值:100,最大值:160}
},
图表区:{顶部:110,左侧:20,右侧:200},
};
var chart=new google.visualization.LineChart(document.getElementById('chart_div'));
图纸();
设定间隔(图纸,500);
var-rowIndex=0;
函数绘图图(){
if(行索引



我想知道是否有可能使工具提示在鼠标悬停在另一个坐标上时跟随鼠标,以延迟但平滑的过渡?此时工具提示出现并立即消失。我想知道是否可以用一种简单的方法来实现它?

Javascript有onmousemove事件监听器。看

    google.charts.load('current', {
callback: function () {
var rawData = [
    [2010, 100, 100],
    [2011, 105, 120],
    [2012, 111, 122],
    [2013, 122, 132],
    [2014, 131, 146],
    [2015, 139, 150],
    [2016, 143, 156],
];


var data = new google.visualization.DataTable({
  "cols": [
    {"id":"","label":"Date","type":'number'},
    {"id":"","label":"Black","type":'number'},
    {"id":"","label":"White","type":"number"}
  ]
});   

var options = {
    backgroundColor: 'transparent',
    focusTarget: 'category',
    lineWidth: 3,
    colors: ['#000'],
    crosshair: { orientation: 'vertical', trigger: 'both', color: 'black' },
    tooltip: { isHtml: true},
    pointSize: 0,
    animation:{
    startup: true,
    duration: 300,
    easing: 'out'
  },
    legend: 'none',
    series: {
        0: { lineDashStyle: [4, 4],tooltip : false, color:'rgb(223, 119, 106)', enableInteractivity: false, format: '0000'},
        1: {color:'black', zIndex:5, format: '0000'},
    },
    hAxis: {
      format: '0000',
      gridlines: { color: 'transparent', count: 6 },
      textStyle: { fontSize: 14, color: 'black' },
      viewWindow: { min: 2010, max: 2016 }
  },
    vAxis:{ 
      gridlines: { count: 7 },
        textPosition: 'none',
      textStyle: { color: 'transparent' },
      viewWindow: { min: 100, max: 160 }
  },
    chartArea: { top: 110, left: 20, right: 200 },
};

var chart = new google.visualization.LineChart(document.getElementById('chart_div'));


drawChart();
setInterval(drawChart, 500);


var rowIndex = 0;
function drawChart() {
  if (rowIndex < rawData.length) {
    data.addRow(rawData[rowIndex++]);
    chart.draw(data, options);
  }
}
},
packages:['corechart']
});
使用onmousemove事件侦听器,您可以获得光标的x&y坐标,并根据需要定位工具提示的位置。最困难的部分是实现坐标之间转换的加速度增量

下面是一个JSBIN演示,演示如何:


将鼠标移到上面的矩形上,并获取鼠标指针的坐标

当鼠标移动到div上时,p元素将显示鼠标指针的水平和垂直坐标,其值从 MouseEvent对象

功能手柄移动(e){ var x=e.clientX; 变量y=e.clientY; var coor=“坐标:(“+x+”,“+y+”); document.getElementById(“demo”).innerHTML=coor; } 函数clearCoor(){ document.getElementById(“demo”).innerHTML=“”; }
Javascript具有onmousemove事件侦听器。看

使用onmousemove事件侦听器,您可以获得光标的x&y坐标,并根据需要定位工具提示的位置。最困难的部分是实现坐标之间转换的加速度增量

下面是一个JSBIN演示,演示如何:


将鼠标移到上面的矩形上,并获取鼠标指针的坐标

当鼠标移动到div上时,p元素将显示鼠标指针的水平和垂直坐标,其值从 MouseEvent对象

功能手柄移动(e){ var x=e.clientX; 变量y=e.clientY; var coor=“坐标:(“+x+”,“+y+”); document.getElementById(“demo”).innerHTML=coor; } 函数clearCoor(){ document.getElementById(“demo”).innerHTML=“”; }
<body>

<div onmousemove="handleMouseMove(event)" onmouseout="clearCoor()"></div>

<p>Mouse over the rectangle above, and get the coordinates of your mouse pointer.</p>

<p>When the mouse is moved over the div, the p element will display the horizontal and vertical coordinates of your mouse pointer, whose values are returned from the clientX and clientY properties on the 
MouseEvent object.</p>

<p id="demo"></p>

<script>
function handleMouseMove(e) {
    var x = e.clientX;
    var y = e.clientY;
    var coor = "Coordinates: (" + x + "," + y + ")";
    document.getElementById("demo").innerHTML = coor;
}

function clearCoor() {
    document.getElementById("demo").innerHTML = "";
}
</script>

</body>