我的图表的图例仅在plotpan
事件发生时出现。这是我updateLegend
在下面找到的函数,我确信程序当然会使用跟踪消息进入
plotpan
但是,自从我包含该功能以来,图例的唯一一次更新是在 aplotpan
发生之后。我不确定是什么原因造成的,因此我无法解决这个问题。这是 JSFiddle,它比以下孤立的代码段更有帮助。
var updateLegendTimeout = null;
var latestPosition = null;
function updateLegend(){
var series = (plot.getData())[0];
legends.eq(0).text(series.label ="x: " + (local_x)+" y: "+ (local_y));
}
placeholder.bind("plothover", function (event, pos, item) {
if (item){
local_x = item.datapoint[0].toFixed(2);
local_y = item.datapoint[1].toFixed(2);
console.log("x:" + local_x + ", " + "y:" + local_y);
}
if (!updateLegendTimeout){
updateLegendTimeout = setTimeout(updateLegend, 50);
updateLegendTimeout = null;
}
});