|
|
|
@ -14,15 +14,15 @@
|
|
|
|
<div id="placeholder" style="width:600px;height:300px"></div>
|
|
|
|
<div id="placeholder" style="width:600px;height:300px"></div>
|
|
|
|
|
|
|
|
|
|
|
|
<p>One of the goals of Flot is to support user interactions intelligently.
|
|
|
|
<p>One of the goals of Flot is to support user interactions intelligently.
|
|
|
|
Try hovering over the graph above and clicking on the points. A
|
|
|
|
Try mousing the above plot.</p>
|
|
|
|
tooltip is easy to build with a bit of jQuery code and the data returned
|
|
|
|
|
|
|
|
from the plot. Note that support for highlighting the points is
|
|
|
|
|
|
|
|
currently missing.</p>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<p id="clickdata"></p>
|
|
|
|
<p id="hoverdata">Mouse hovers at
|
|
|
|
|
|
|
|
(<span id="x">0</span>, <span id="y">0</span>). <span id="clickdata"></span></p>
|
|
|
|
|
|
|
|
|
|
|
|
<p id="hoverdata" style="display:none">Mouse hovers at
|
|
|
|
<p>A tooltip is easy to build with a bit of jQuery code and the
|
|
|
|
(<span id="x"></span>, <span id="y"></span>).</p>
|
|
|
|
data returned from the plot.</p>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<p><input id="enableTooltip" type="checkbox">Enable tooltip</p>
|
|
|
|
|
|
|
|
|
|
|
|
<script id="source" language="javascript" type="text/javascript">
|
|
|
|
<script id="source" language="javascript" type="text/javascript">
|
|
|
|
$(function () {
|
|
|
|
$(function () {
|
|
|
|
@ -32,11 +32,14 @@ $(function () {
|
|
|
|
cos.push([i, Math.cos(i)]);
|
|
|
|
cos.push([i, Math.cos(i)]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$.plot($("#placeholder"),
|
|
|
|
var plot = $.plot($("#placeholder"),
|
|
|
|
[ { data: sin, label: "sin(x)"}, { data: cos, label: "cos(x)" } ],
|
|
|
|
[ { data: sin, label: "sin(x)"}, { data: cos, label: "cos(x)" } ],
|
|
|
|
{ lines: { show: true },
|
|
|
|
{ lines: { show: true },
|
|
|
|
points: { show: true },
|
|
|
|
points: { show: true },
|
|
|
|
grid: { hoverable: true, clickable: true } });
|
|
|
|
selection: { mode: "xy" },
|
|
|
|
|
|
|
|
grid: { hoverable: true, clickable: true },
|
|
|
|
|
|
|
|
yaxis: { min: -1.2, max: 1.2 }
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
function showTooltip(x, y, contents) {
|
|
|
|
function showTooltip(x, y, contents) {
|
|
|
|
$('<div id="tooltip">' + contents + '</div>').css( {
|
|
|
|
$('<div id="tooltip">' + contents + '</div>').css( {
|
|
|
|
@ -55,29 +58,31 @@ $(function () {
|
|
|
|
$("#placeholder").bind("plothover", function (event, pos, item) {
|
|
|
|
$("#placeholder").bind("plothover", function (event, pos, item) {
|
|
|
|
$("#x").text(pos.x.toFixed(2));
|
|
|
|
$("#x").text(pos.x.toFixed(2));
|
|
|
|
$("#y").text(pos.y.toFixed(2));
|
|
|
|
$("#y").text(pos.y.toFixed(2));
|
|
|
|
$("#hoverdata").show();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (item) {
|
|
|
|
if ($("#enableTooltip:checked").length > 0) {
|
|
|
|
if (previousPoint != item.datapoint) {
|
|
|
|
if (item) {
|
|
|
|
previousPoint = item.datapoint;
|
|
|
|
if (previousPoint != item.datapoint) {
|
|
|
|
|
|
|
|
previousPoint = item.datapoint;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$("#tooltip").remove();
|
|
|
|
|
|
|
|
var x = item.datapoint[0].toFixed(2),
|
|
|
|
|
|
|
|
y = item.datapoint[1].toFixed(2);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
showTooltip(item.pageX, item.pageY,
|
|
|
|
|
|
|
|
item.series.label + " of " + x + " = " + y);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
|
|
|
$("#tooltip").remove();
|
|
|
|
$("#tooltip").remove();
|
|
|
|
var x = item.datapoint[0].toFixed(2),
|
|
|
|
previousPoint = null;
|
|
|
|
y = item.datapoint[1].toFixed(2);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
showTooltip(item.pageX, item.pageY,
|
|
|
|
|
|
|
|
item.series.label + " of " + x + " = " + y);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
|
|
|
|
$("#tooltip").remove();
|
|
|
|
|
|
|
|
previousPoint = null;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
$("#placeholder").bind("plotclick", function (event, pos, item) {
|
|
|
|
$("#placeholder").bind("plotclick", function (event, pos, item) {
|
|
|
|
if (item) {
|
|
|
|
if (item) {
|
|
|
|
$("#clickdata").text("You clicked point " + item.dataIndex + " in " + item.series.label);
|
|
|
|
$("#clickdata").text("You clicked point " + item.dataIndex + " in " + item.series.label + ".");
|
|
|
|
|
|
|
|
plot.highlight(item.series, item.datapoint);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|