Skip to content

Commit 3a979e9

Browse files
author
LaoBian
committed
cgi动图项目
1 parent 5afce86 commit 3a979e9

File tree

5 files changed

+2213
-37
lines changed

5 files changed

+2213
-37
lines changed

.idea/workspace.xml

Lines changed: 60 additions & 35 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cgiProject/cgi-bin/jsonData.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import json
2+
import time
3+
import random
4+
5+
now = time.strftime("%H:%M:%S",time.localtime())
6+
num = random.randint(1,11)
7+
8+
result = {"now":now,"num":num}
9+
10+
josn_result = json.dumps(result) #将字典转换为json
11+
#loads 将json转换为字典
12+
13+
print("content-type:application/json") #返回响应的头部,具体描述的要返回的内容类型,在cgi当中用print进行返回
14+
print("\n") #返回头部结束
15+
print(josn_result) #返回响应的body

cgiProject/image.html

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,55 @@
33
<title>
44
image
55
</title>
6+
<script src="js/jquery-3.1.1.min.js"></script>
7+
<script src="js/Chart.min.js"></script>
68
</head>
79
<body>
8-
<img src="https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1562231356365&di=0d1ca146f287f56b35b9c271e0cc08ac&imgtype=0&src=http%3A%2F%2Fwww.zhongaigou.com%2Fuploadfiles%2F33191%2F9133%2520%2528295%2529.jpg">
9-
</body>
10+
<canvas id="panel" height="330px" width="500px">
11+
12+
</canvas>
13+
<script>
14+
$(
15+
function () {
16+
var can = $("#panel").get(0).getContext("2d");//设置为2d画布
17+
var canData = {
18+
labels:["a","b","c","d","e","f"], //x轴的坐标
19+
datasets:[
20+
{
21+
fillColor: "rgba(255,255,0,0.2)", //线条下的填充色
22+
strokeColor: "rgba(0,255,0,1)", //线条颜色
23+
data:[1,2,3,2,1,5] //y轴对应x轴的数据
24+
}
25+
]
26+
};
27+
var line = new Chart(can).Line(canData);
28+
setInterval(
29+
function () {
30+
$.ajax(
31+
{
32+
type:"get", //ajax请求的类型
33+
url:"/cgi-bin/jsonData.py", //ajax请求的地址
34+
data:"", //请求需要携带的数据
35+
success: function (data) {
36+
line.addData(
37+
[data["num"]],
38+
data["now"]
39+
);
40+
var len = line.datasets[0].points.length; //获取点个数
41+
if(len > 8){
42+
line.removeData()
43+
}
44+
},//回调函数,如果请求成功,ajax自动调用当前函数,将返回结果传递给data
45+
error: function (error) {
46+
console.log(error)
47+
}//回调函数,如果请求失败,ajax自动调用当前函数,将返回错误传递给error
48+
}
49+
)//使用ajax
50+
},1000
51+
)
1052

53+
}
54+
)
55+
</script>
56+
</body>
1157
</html>

0 commit comments

Comments
 (0)