Customize tooltip in FLOT graph

点点圈 提交于 2019-12-06 16:41:17

I'm not using the flot tooltip. There is easier way to show tooltip and customize it. Check out this fiddler:

http://jsfiddle.net/Margo/yKG7X/5/

$("#placeholder").bind("plothover", function (event, pos, item) { if (item) {
$("#tooltip").remove();

                var x = item.datapoint[0],
                    y = item.datapoint[1];
                showTooltip(item.pageX, item.pageY, x + " / " + y );
                }
});
function showTooltip(x, y, contents) {
    $('<div id="tooltip">' + contents + '</div>').css({
        position: 'absolute',
        display: 'none',
        top: y + 5,
        left: x + 5,
        border: '1px solid #fdd',
        padding: '2px',
        'background-color': '#fee',
        opacity: 0.80
    }).appendTo("body").fadeIn(200).fadeOut(6000);
}

Hope it helps :)

The documentation states that:

If you require even more control over how the tooltip is generated you can pass a callback function(label, xval, yval, flotItem) that must return a string with the format described.

xval is the numeric x axis value where the tooltip is located. It is not a string. The replace method it is failing on is the standard string.replace:

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