jQuery Flot - 显示准确的值

时间:2013-04-12 02:07:20

标签: jquery tooltip decimal flot

我注意到jQuery Flot正在对结果进行四舍五入。但是当我将鼠标悬停在工具提示中的峰和谷上时,我想显示结果的实际十进制值。但不是x或y轴标签,而是图形结果本身。

所以不是“44”,而是“44.05”。

我能做些什么才能做到这一点?我所看到的一切都只是轴标签。

2 个答案:

答案 0 :(得分: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;
                    }

            });

答案 1 :(得分:1)

要在工具提示中显示准确的值,请执行以下操作:

tooltipOpts: {
    content: "%s : %y.2",
}

哪里" y"是你的值,2是小数位数。