我需要使用 python 和每 10 秒随机 2 个整数显示 google 图表,将整数替换到图表中,然后显示在浏览器上。
这是我的代码,我是 python 新手,不知道我的代码有什么问题
import random
import time
while True:
f = open('message.html', 'w')
message1 = '<html><head><script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script><script type="text/javascript">'
message2 = "google.charts.load('current', {'packages':['corechart']});google.charts.setOnLoadCallback(drawChart);function drawChart() {var data = google.visualization.arrayToDataTable([ ['Task', 'Hours per Day'],"
message3 = "['Work', "
message4 = "], ['Sleep',"
message5 = "]]);var options = {title: 'My Daily Activities'};var chart = new google.visualization.PieChart(document.getElementById('piechart'));chart.draw(data, options);}</script></head><body>"
message6 = '<div id="piechart" style="width: 900px; height: 500px;"></div></body></html>'
a = random.randint(0, 101)
b = random.randint(0, 101)
message = message1 + message2 + message3 + str(a) + message4 + str(b) + message5 + message6
f.write(message)
time.sleep(10)
f.close()
我尝试在终端中打印 a 和 b,它完全随机,但图表没有显示在浏览器上。
饮歌长啸
相关分类