问题
I notice that jQuery Flot is rounding down the results. But I want to show the actual decimal value for the result when you hover over the peaks and valleys in the tooltip. But not the x or y axis labels, but the graph result itself.
So instead of "44", I want "44.05".
Is there anything I can do to make that work? Everything I'm seeing is just for the axis labels.
回答1:
The tool tip should allow you to do this - have a look at this fiddle 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;
}
});
回答2:
To show accurate values in the tooltip make this:
tooltipOpts: {
content: "%s : %y.2",
}
Where "y" is your value and 2 is the number of decimal places.
来源:https://stackoverflow.com/questions/15961948/jquery-flot-display-accurate-values