forked from PythonBian/Python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimage.html
More file actions
57 lines (55 loc) · 1.48 KB
/
image.html
File metadata and controls
57 lines (55 loc) · 1.48 KB
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
<html>
<head>
<title>
image
</title>
<script src="js/jquery-3.1.1.min.js"></script>
<script src="js/Chart.min.js"></script>
</head>
<body>
<canvas id="panel" height="330px" width="500px">
</canvas>
<script>
$(
function () {
var can = $("#panel").get(0).getContext("2d");//设置为2d画布
var canData = {
labels:["a","b","c","d","e","f"], //x轴的坐标
datasets:[
{
fillColor: "rgba(255,255,0,0.2)", //线条下的填充色
strokeColor: "rgba(0,255,0,1)", //线条颜色
data:[1,2,3,2,1,5] //y轴对应x轴的数据
}
]
};
var line = new Chart(can).Line(canData);
setInterval(
function () {
$.ajax(
{
type:"get", //ajax请求的类型
url:"/cgi-bin/jsonData.py", //ajax请求的地址
data:"", //请求需要携带的数据
success: function (data) {
line.addData(
[data["num"]],
data["now"]
);
var len = line.datasets[0].points.length; //获取点个数
if(len > 8){
line.removeData()
}
},//回调函数,如果请求成功,ajax自动调用当前函数,将返回结果传递给data
error: function (error) {
console.log(error)
}//回调函数,如果请求失败,ajax自动调用当前函数,将返回错误传递给error
}
)//使用ajax
},1000
)
}
)
</script>
</body>
</html>