2012-04-16 73 views
13

我有一個問題,我似乎無法追查。我使用Flot來繪製一些數據,非常簡單。我想添加你在這裏看到的懸停效果:Flot ExampleJquery Flot「plothover」事件不起作用

不幸的是,在任何情況下我都無法得到'plothover'事件觸發。這是從代碼的簡短片段:

$.plot($chartArea, eventData, eventOptions); 

$chartArea.bind("plothover", function (event, pos, item) { 
    console.log('hovering!'); 
}); 

是否有你需要設置的選項反對啓用此行爲的東西嗎?謝謝!

+0

你能告訴我們你的代碼的一個可行的例子上的jsfiddle吧?以這種方式發現問題要容易得多。 – Aidanc 2012-04-16 21:17:46

+0

你是對的,但只要我發佈這個,我意識到我忘了一些東西,看看我的答案... – gabaum10 2012-04-16 21:18:52

回答

38

就像一個白癡,我忘了包括網格選項。查看對象:

eventOptions = { 
    points: { 
     show: true 
    }, 
    lines: { 
     show: true 
    }, 
    grid: { hoverable: true, clickable: true }, 
    xaxis: { 
     min:earliestMessage.timestamp, 
     max:currentTime, 
     mode:"time", 
     ticks:10 
    } 
}; 

注意網格參數。這就是缺少的。咄!

:)

+0

謝謝,有同樣的問題,「plotclick」事件,直到我意識到我已設置網格可點擊假! – Jerry 2015-01-20 12:14:00

2

我不知道什麼$ chartArea是在你的代碼,但讓我們試試這樣:

var chartArea = $("#placeholder"); // your chart div 

$.plot(chartArea, eventData, eventOptions); 

$(chartArea).bind("plothover", function (event, pos, item) { 
    console.log('hovering!'); 
}); 
+0

適用於我,給予id名稱和給出元素名稱有什麼區別。 – ddarz4u 2014-11-11 19:59:07