2013-04-12 25 views
1

我注意到,jQuery的海軍報是四捨五入的結果。但是當您將鼠標懸停在工具提示中的峯和谷上時,我想顯示結果的實際十進制值。但不是x或y軸標籤,而是圖表結果本身。jQuery的海軍報 - 顯示準確的數值

所以不是 「44」,我想 「44.05」。

有什麼我可以做,使這項工作?我看到的所有內容都是針對軸標籤的。

回答

3

刀尖應該讓你做到這一點 - 看看這個小提琴http://jsfiddle.net/Rnusy/

var previousPoint = null; 
     $("#placeholder").bind("plothover", function (event, pos, item){ 
      $("#x").text(pos.x.toFixed(2)); 
      $("#y").text(pos.y.toFixed(2)); 
      if (item) { 
       if (previousPoint != item.dataIndex){ 
        previousPoint = item.dataIndex; 

        $("#tooltip").remove(); 
        var x = item.datapoint[0].toFixed(2), 
         y = item.datapoint[1].toFixed(2); 

         showTooltip(item.pageX, item.pageY, y); 
                } 
        } 
       else { 
        $("#tooltip").remove(); 
        previousPoint = null; 
        } 

      }); 
+0

變化toFixed(2)如果你想兩個以上的小數位 – Blake

1

要顯示工具提示精確的值使這個:

​​

其中「Y」是您的值和2是小數位數。