Last active
December 27, 2015 01:59
-
-
Save detailyang/7249168 to your computer and use it in GitHub Desktop.
flot plugin for jquery
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var d1 = [[0, 1], [1, 2], [4, 5], [6, 100]]; | |
var data = [ | |
{label: "shit", data: d1} | |
] | |
var options = { | |
series: { | |
lines: { show: true}, | |
points: {show: true} | |
}, | |
grid: {clickable: true, hoverable: true}, | |
xaxis:{ | |
font: { | |
color: "#f9f9f9", | |
}, | |
}, | |
yaxis: { | |
font: { | |
color: "#f9f9f9", | |
}, | |
} | |
} | |
$.plot($("#traffic-canvas"), data, options);//这个位置指定了图表显示在什么位置 | |
// 邦定事件 | |
$("#traffic-canvas").bind("plothover", function (event, pos, item) { | |
if (item) { | |
var x = item.datapoint[0].toFixed(2), | |
y = item.datapoint[1].toFixed(2); | |
showTooltip(item.pageX, item.pageY, | |
"X:" + x + " Y:" + y); | |
}else { | |
$("#tooltip").remove(); | |
} | |
}); | |
// 悬浮点时进行提示 | |
function showTooltip(x, y, contents) { | |
$('<div id="tooltip">' + contents + '</div>').css( { | |
position: 'absolute', | |
display: 'none', | |
top: y + 5, | |
left: x + 5, | |
padding: '2px', | |
'background-color': 'rgba(51, 51, 51 ,0.5)', | |
}).appendTo("body").fadeIn(200); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment