root / hci / trunk / eneraptor-web-app / web-app / js / flot / examples / annotating.html @ 69
History | View | Annotate | Download (2.72 KB)
1 |
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
---|---|
2 |
<html>
|
3 |
<head>
|
4 |
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> |
5 |
<title>Flot Examples</title> |
6 |
<link href="layout.css" rel="stylesheet" type="text/css"></link> |
7 |
<!--[if IE]><script language="javascript" type="text/javascript" src="../excanvas.min.js"></script><![endif]-->
|
8 |
<script language="javascript" type="text/javascript" src="../jquery.js"></script> |
9 |
<script language="javascript" type="text/javascript" src="../jquery.flot.js"></script> |
10 |
</head>
|
11 |
<body>
|
12 |
<h1>Flot Examples</h1> |
13 |
|
14 |
<div id="placeholder" style="width:600px;height:300px;"></div> |
15 |
|
16 |
<p>Flot has support for simple background decorations such as
|
17 |
lines and rectangles. They can be useful for marking up certain |
18 |
areas. You can easily add any HTML you need with standard DOM |
19 |
manipulation, e.g. for labels. For drawing custom shapes there is |
20 |
also direct access to the canvas.</p>
|
21 |
|
22 |
<script id="source" language="javascript" type="text/javascript"> |
23 |
$(function () {
|
24 |
// generate a dataset
|
25 |
var d1 = [];
|
26 |
for (var i = 0; i < 20; ++i)
|
27 |
d1.push([i, Math.sin(i)]);
|
28 |
|
29 |
var data = [{ data: d1, label: "Pressure", color: "#333" }];
|
30 |
|
31 |
// setup background areas
|
32 |
var markings = [
|
33 |
{ color: '#f6f6f6', yaxis: { from: 1 } },
|
34 |
{ color: '#f6f6f6', yaxis: { to: -1 } },
|
35 |
{ color: '#000', lineWidth: 1, xaxis: { from: 2, to: 2 } },
|
36 |
{ color: '#000', lineWidth: 1, xaxis: { from: 8, to: 8 } }
|
37 |
];
|
38 |
|
39 |
var placeholder = $("#placeholder");
|
40 |
|
41 |
// plot it
|
42 |
var plot = $.plot(placeholder, data, {
|
43 |
bars: { show: true, barWidth: 0.5, fill: 0.9 },
|
44 |
xaxis: { ticks: [], autoscaleMargin: 0.02 },
|
45 |
yaxis: { min: -2, max: 2 },
|
46 |
grid: { markings: markings }
|
47 |
});
|
48 |
|
49 |
// add labels
|
50 |
var o;
|
51 |
|
52 |
o = plot.pointOffset({ x: 2, y: -1.2});
|
53 |
// we just append it to the placeholder which Flot already uses
|
54 |
// for positioning
|
55 |
placeholder.append('<div style="position:absolute;left:' + (o.left + 4) + 'px;top:' + o.top + 'px;color:#666;font-size:smaller">Warming up</div>');
|
56 |
|
57 |
o = plot.pointOffset({ x: 8, y: -1.2});
|
58 |
placeholder.append('<div style="position:absolute;left:' + (o.left + 4) + 'px;top:' + o.top + 'px;color:#666;font-size:smaller">Actual measurements</div>');
|
59 |
|
60 |
// draw a little arrow on top of the last label to demonstrate
|
61 |
// canvas drawing
|
62 |
var ctx = plot.getCanvas().getContext("2d");
|
63 |
ctx.beginPath();
|
64 |
o.left += 4;
|
65 |
ctx.moveTo(o.left, o.top);
|
66 |
ctx.lineTo(o.left, o.top - 10);
|
67 |
ctx.lineTo(o.left + 10, o.top - 5);
|
68 |
ctx.lineTo(o.left, o.top);
|
69 |
ctx.fillStyle = "#000";
|
70 |
ctx.fill();
|
71 |
});
|
72 |
</script>
|
73 |
|
74 |
</body>
|
75 |
</html>
|