JSFiddle - React, Tailwind, and code Playground
HTML
<script src="http://www.pureexample.com/js/flot/jquery.flot.min.js"></script>
<div id="placeholder" style="width:500px;height:300px;"></div>
JavaScript
var data = [];
data = [[3,36],[5,29],[7,33],[9,28]];
var info = []
info = ["addinfo1", "addinfo2", "addinfo3", "addinfo4"];
dataLine = [];
dataLine.push(data);
$.plot($("#placeholder"), dataLine, {
grid: {backgroundColor: "#E5E5E5", hoverable: true},
points: {show: true, radius: 4},
lines: { show: true }
});
function showTooltip(x, y, contents) {
$('<div id="tooltip">' + contents + '</div>').css( {
position: 'absolute',
display: 'none',
top: y - 40,
left: x - 30,
border: '1px solid #fdd',
padding: '2px',
'background-color': '#fee',
opacity: 0.80
}).appendTo("body").fadeIn(200);
}
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,
x + " "+ info[item.dataIndex]);
}
}
else {
$("#tooltip").remove();
previousPoint = null;
}
});