dragonfeet2012 dragonfeet2012 - 1 month ago 16
jQuery Question

jQuery Flot - Display accurate values

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.

Answer

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;
                    }

            });