[英]Prevent jQuery Flot to convert numbers to decimal
我發現jquery flot給數字增加了十進制,因此12
將是12.00
。
這是一個示例:
$(function() {
var data = [ [0, 3], [4, 8], [8, 5], [9, 13] ];
$.plot($("#placeholder"), [data], {
grid: {
hoverable: true,
clickable: true
},
series: { lines: {show: true},
points:{show: true}
}
});
$("<div id='tooltip'></div>").css({
position: "absolute",
display: "none",
border: "1px solid #fdd",
padding: "2px",
"background-color": "#fee",
opacity: 0.80
}).appendTo("body");
$("#placeholder").bind("plothover", function(event, pos, item) {
if (item) {
var x = item.datapoint[0].toFixed(2),
y = item.datapoint[1].toFixed(2);
$("#tooltip").html( "x is: " + x + " -- y is: " + y)
.css({
top: item.pageY + 5,
left: item.pageX + 5
})
.fadeIn(200);
} else {
$("#tooltip").hide();
}
});
});
它顯示帶有工具提示的圖表。 當您將鼠標懸停在所看到的點上時
x is: 4.00 -- y is 8.00
我該如何解決?
這些代碼行使工具提示值浮動。
var x = item.datapoint[0].toFixed(2),
y = item.datapoint[1].toFixed(2);
要使x和y為整數,
var x = item.datapoint[0],
y = item.datapoint[1];
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.