/
interacting.html
71 lines (66 loc) · 2.59 KB
/
interacting.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Flot Examples</title>
<link href="layout.css" rel="stylesheet" type="text/css">
<!--[if IE]><script language="javascript" type="text/javascript" src="../excanvas.pack.js"></script><![endif]-->
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js"></script>
<script type="text/javascript" src="../jquery.flot.js"></script>
<script type="text/javascript">
$(document).ready( function () {
// create some datasets
var d1 = [];
for (var i = 0; i < 14; i += 0.5)
d1.push( { x: i, y: Math.sin(i/8) +1 } );
var d2 = [];
for (var i = 0; i < 14; i += 0.5)
d2.push( { x: i, y: Math.sin(i/-3) } );
// plot the graph into '#placeholder'
plot = $.plot(
$("#placeholder"),
[ { data: d1, label: "Yellow" },
{ data: d2, label: "Blue" } ],
{ hints: {
show: true,
hintFormatter: function( datapoint ) {
hintStr = "";
for( var key in datapoint ) {
if( key[0] == '_' ) { continue; } // skip internal members
hintStr += "<strong>" + key + ":</strong> " +
datapoint[key].toFixed(2) + "<br/>";
}
return hintStr;
} },
points: { show: true },
lines: { show: true },
legend: { position: 'sw' },
grid: {
clickable: true,
hoverable: true,
hoverFill: '#444',
hoverRadius: 5
}
} );
// setup event handlers
$("#placeholder").bind( "plotclick", function( e, pos ) {
if( !pos.selected ) { return; }
plot.highlightSelected( pos.selected );
x = pos.selected.x.toFixed( 2 );
y = pos.selected.y.toFixed( 2 );
$("#result").text( 'You clicked on (' + x + ', ' + y + ')' );
} );
$("#placeholder").bind( "plotmousemove", function( e, pos ) {
if( !pos.selected ) { return; }
plot.highlightSelected( pos.selected );
} );
});
</script>
</head>
<body>
<h1>Flot Examples</h1>
<div id="placeholder" style="width: 600px; height: 300px;"></div>
<p>Try hovering or clicking on the plot above. <span id="result"></span></p>
</body>
</html>