$.fn.UseTooltip = function () {
var PrePoint = null, PreLabel = null;
$(this).bind("plothover", function (event, pos, item) {
if (item) {
if ((PreLabel != item.series.label) || (PrePoint != item.dataIndex)) {
PrePoint = item.dataIndex;
PreLabel = item.series.label;
$("#tooltip").remove();
$(this).css({
"cursor": "pointer"
})
if (item.seriesIndex == 0) {
ShowTooltip(
item.pageX + 100,
item.pageY - 10,
"#f7d373",
result.Date[item.dataIndex] + " 铝锭价: " + item.series.data[item.dataIndex][1]);
}
}
}
else {
PrePoint = null;
PreLabel = null;
$(this).css({
"cursor": "auto"
});
$("#tooltip").remove();
}
});
};
if (PriceArr.length > 0) {
$.plot($("#placeholder"), DataSet, Options);
$("#placeholder").UseTooltip();
}
}
//提示框
function ShowTooltip(x, y, color, contents) {
$('<div id="tooltip">' + contents + '</div>').css({
position: 'absolute',
display: 'none',
top: y - 40,
left: x - 120,
border: '2px solid ' + color,
padding: '3px',
'font-size': '9px',
'border-radius': '5px',
'background-color': '#fff',
'font-family': 'Verdana, Arial, Helvetica, Tahoma, sans-serif',
opacity: 0.9
}).appendTo("body").fadeIn(200);
}
</script>
</head>
<body>
<div id="placeholder" style="width:400px;height:200px;"></div>
</body>
</html>
2、运行效果图如下:

附:jquery.flot.js插件本站下载地址:
//www.jb51.net/jiaoben/22143.html
更多关于jQuery相关内容感兴趣的读者可查看本站专题:《jQuery常用插件及用法总结》、《jquery中Ajax用法总结》、《jQuery表格(table)操作技巧汇总》、《jQuery扩展技巧总结》、《jQuery常见经典特效汇总》及《jquery选择器用法总结》
希望本文所述对大家jQuery程序设计有所帮助。










