我需要使用 python 和每 10 秒隨機 2 個整數顯示 google 圖表,將整數替換到圖表中,然后顯示在瀏覽器上。這是我的代碼,我是 python 新手,不知道我的代碼有什么問題import randomimport timewhile 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,它完全隨機,但圖表沒有顯示在瀏覽器上。
使用python顯示google圖表并每10秒刷新一次數據
慕田峪9158850
2023-12-05 15:21:06