動的データをリアルタイムでグラフに表示する必要があります。 それで、毎秒更新されたデータで新しいグラフを描く必要があります。python cgiを使った空のブラウザ画面
問題は、私は代わりに、更新されたデータと簡単なグラフを得るためのブラウザ に前の出力を空とすることができないということです 私はここのコードであるグラフ
の多くを得ます。現在ランダムなデータを持っています
def graph(data):
X,Y = 500, 275 #image width and height
img = Image.new("RGB", (X,Y), "#FFFFFF")
draw = ImageDraw.Draw(img)
#draw some axes and markers
for i in range(X/10):
draw.line((i*10+30, Y-15, i*10+30, 20), fill="#DDD")
if i % 5 == 0:
draw.text((i*10+15, Y-15), `i*10`, fill="#000")
for j in range(1,Y/10-2):
draw.text((0,Y-15-j*10), `j*10`, fill="#000")
draw.line((20,Y-19,X,Y-19), fill="#000")
draw.line((19,20,19,Y-18), fill="#000")
for i in range(1,len(data)):
draw.line((i+20,Y-20,i+20,Y-20-data[i]), fill="#000")
rtime = str(time.time())
img.save("../images/out.png"+rtime, "PNG")
htmlBody = []
htmlBody.insert(0, 'Content-type: text/html; charset=UTF-8\n')
htmlBody.append('<html>')
htmlBody.append('<body>')
htmlBody.append('<img src=\"../images/out.png'+rtime+'\" alt=\"\" />')
htmlBody.append("</body>")
htmlBody.append('</html>')
sys.stdout.flush()
sys.stdout.write('\n'.join(htmlBody))
sys.stdout.flush()
data = []
if (printgraph!=None):
sys.stdout = sys.stderr = oldsysout
for i in range(1,5):
data.append(int(250*(random.random())))
graph(data)
sys.stdout.flush()
time.sleep(1)
exit()