| 3284 |
vikas |
1 |
About
|
|
|
2 |
-----
|
|
|
3 |
|
|
|
4 |
Flot is a Javascript plotting library for jQuery. Read more at the
|
|
|
5 |
website:
|
|
|
6 |
|
|
|
7 |
http://code.google.com/p/flot/
|
|
|
8 |
|
|
|
9 |
Take a look at the examples linked from above, they should give a good
|
|
|
10 |
impression of what Flot can do and the source code of the examples is
|
|
|
11 |
probably the fastest way to learn how to use Flot.
|
|
|
12 |
|
|
|
13 |
|
|
|
14 |
Installation
|
|
|
15 |
------------
|
|
|
16 |
|
|
|
17 |
Just include the Javascript file after you've included jQuery.
|
|
|
18 |
|
|
|
19 |
Generally, all browsers that support the HTML5 canvas tag are
|
|
|
20 |
supported.
|
|
|
21 |
|
|
|
22 |
For support for Internet Explorer < 9, you can use Excanvas, a canvas
|
|
|
23 |
emulator; this is used in the examples bundled with Flot. You just
|
|
|
24 |
include the excanvas script like this:
|
|
|
25 |
|
|
|
26 |
<!--[if lte IE 8]><script language="javascript" type="text/javascript" src="excanvas.min.js"></script><![endif]-->
|
|
|
27 |
|
|
|
28 |
If it's not working on your development IE 6.0, check that it has
|
|
|
29 |
support for VML which Excanvas is relying on. It appears that some
|
|
|
30 |
stripped down versions used for test environments on virtual machines
|
|
|
31 |
lack the VML support.
|
|
|
32 |
|
|
|
33 |
You can also try using Flashcanvas (see
|
|
|
34 |
http://code.google.com/p/flashcanvas/), which uses Flash to do the
|
|
|
35 |
emulation. Although Flash can be a bit slower to load than VML, if
|
|
|
36 |
you've got a lot of points, the Flash version can be much faster
|
|
|
37 |
overall. Flot contains some wrapper code for activating Excanvas which
|
|
|
38 |
Flashcanvas is compatible with.
|
|
|
39 |
|
|
|
40 |
You need at least jQuery 1.2.6, but try at least 1.3.2 for interactive
|
|
|
41 |
charts because of performance improvements in event handling.
|
|
|
42 |
|
|
|
43 |
|
|
|
44 |
Basic usage
|
|
|
45 |
-----------
|
|
|
46 |
|
|
|
47 |
Create a placeholder div to put the graph in:
|
|
|
48 |
|
|
|
49 |
<div id="placeholder"></div>
|
|
|
50 |
|
|
|
51 |
You need to set the width and height of this div, otherwise the plot
|
|
|
52 |
library doesn't know how to scale the graph. You can do it inline like
|
|
|
53 |
this:
|
|
|
54 |
|
|
|
55 |
<div id="placeholder" style="width:600px;height:300px"></div>
|
|
|
56 |
|
|
|
57 |
You can also do it with an external stylesheet. Make sure that the
|
|
|
58 |
placeholder isn't within something with a display:none CSS property -
|
|
|
59 |
in that case, Flot has trouble measuring label dimensions which
|
|
|
60 |
results in garbled looks and might have trouble measuring the
|
|
|
61 |
placeholder dimensions which is fatal (it'll throw an exception).
|
|
|
62 |
|
|
|
63 |
Then when the div is ready in the DOM, which is usually on document
|
|
|
64 |
ready, run the plot function:
|
|
|
65 |
|
|
|
66 |
$.plot($("#placeholder"), data, options);
|
|
|
67 |
|
|
|
68 |
Here, data is an array of data series and options is an object with
|
|
|
69 |
settings if you want to customize the plot. Take a look at the
|
|
|
70 |
examples for some ideas of what to put in or look at the reference
|
|
|
71 |
in the file "API.txt". Here's a quick example that'll draw a line from
|
|
|
72 |
(0, 0) to (1, 1):
|
|
|
73 |
|
|
|
74 |
$.plot($("#placeholder"), [ [[0, 0], [1, 1]] ], { yaxis: { max: 1 } });
|
|
|
75 |
|
|
|
76 |
The plot function immediately draws the chart and then returns a plot
|
|
|
77 |
object with a couple of methods.
|
|
|
78 |
|
|
|
79 |
|
|
|
80 |
What's with the name?
|
|
|
81 |
---------------------
|
|
|
82 |
|
|
|
83 |
First: it's pronounced with a short o, like "plot". Not like "flawed".
|
|
|
84 |
|
|
|
85 |
So "Flot" rhymes with "plot".
|
|
|
86 |
|
|
|
87 |
And if you look up "flot" in a Danish-to-English dictionary, some up
|
|
|
88 |
the words that come up are "good-looking", "attractive", "stylish",
|
|
|
89 |
"smart", "impressive", "extravagant". One of the main goals with Flot
|
|
|
90 |
is pretty looks.
|