Use of jquery plugin Flot

Source: Internet
Author: User

Features: Easy to use, good interactive effect, support dynamic display

Use: 1.view<div id= "Flot" ></div>2.jsvar dataSet = [];//places where graphical objects are stored
var obj1 = {label"Obj1", Color:"#00FFFF", data:d atas, linesshow}};
Data: Is what you want to show the graph object, support JSON format
Dataset.push (Obj1,...);
varOptions= {//Chart presentation style
Grid: {
BackgroundColor: "#000000",
Tickcolor: "#008040",
Hoverable: True
Clickable: True
},
YAxis: { Min: 0},
Xaxis: { Mode: ' Time ',
Ticksize: [5, "Minute"],
TimeFormat: "%h:%m%p",//format string to use
Min: currenttime-3600000,//1 Hour
Max: CurrentTime,
TimeZone: "Browser",
Twelvehourclock: True//or time in time mode
},
Series: {
Lines: {
LineWidth: 1,
Fill: True
FillColor: {
Colors: [
{
Opacity: 0.4
},
{
Opacity: 0
}
]
},
Steps: False
}
}
};
Chart initialization
$ (document). Ready (function () {
     $.plot ($ (' #flot '), dataset,options);
});
Displays the node data information when the mouse is moved to the graph data node
VarPreviouspoint =Null
$("#flot").Bind("Plothover",
function(Event,POS,Item) {
If(item) {
If(Previouspoint! = Item. )Dataindex) {
Previouspoint = Item.Dataindex;

$("#tooltip").Remove();
VarItem_series_label = Item.Series.Label;
Varx = Item.Datapoint[0].ToFixed(2),
y = Item.Datapoint[1].ToFixed(2);
Varx_date =NewDate (number (x));
Showtooltip(
Item.PageX,
Item.Pagey,
"Item:"+ Item_series_label +"</br>value:"+ y + item_p
+ "</br>time:"+ x_date.toLocaleString()
);
}
}Else{
$("#tooltip").Remove();
Previouspoint =Null
}
}
);

Show coordinate follow
function Showtooltip(x,y,contents) {
$(' <div id= ' tooltip > '+ contents +' </div> ').Css( {
Position: ' Absolute ',
Display: ' None ',
Top: Y +5,
Left: X +5,
Border: ' 1px solid #000 ',
Padding: ' 2px ',
' Background-color ': ' #fee ',
Opacity: 0.80
}).AppendTo("Body").FadeIn(1);
}
Dynamic display
Encapsulate the chart, request data periodically and refresh the chart (the code is a bit ...). )

Use of jquery plugin Flot

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.