jQuery Flot - Display accurate values

对着背影说爱祢 提交于 2020-01-05 07:36:48

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!