Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 5251

MicroPython • Re: How to draw simple chart on client side from server data

$
0
0
After testing nothing happend on client side. Size and colour normal, but no chart.
Printed response on Pico:

Code:

>>> %Run -c $EDITOR_CONTENTasyncio.run(main())ip = 192.168.64.219<!DOCTYPE html><html></body> <body style="background-color:powderblue;"></body><head><meta name="viewport" content="width=device-width, initial-scale=1"><link rel="icon" href="data:,"><style>html { font-family: Helvetica; display: inline-block; margin: 0px auto; text-align: center;}.button { background-color: #4CAF50; border: 2px solid #000000;; color: white; padding: 15px 32px; text-align: center; text-decoration: none; display: inline-block; font-size: 16px; margin: 4px 2px; cursor: pointer; }.buttonRed { background-color: #d11d53; border: 2px solid #000000;; color: white; padding: 15px 32px; text-align: center; text-decoration: none; display: inline-block; font-size: 16px; margin: 4px 2px; cursor: pointer; }text-decoration: none; font-size: 30px; margin: 2px; cursor: pointer;}</style></head><body><center><h1>Garazna vrata</h1></center><br><br><form><center><center> <button class="button" name="DOOR" value="UP" type="submit">Odpri</button><br><br><center> <button class="buttonRed" name="DOOR" value="STOP" type="submit">Get Temp.</button><br><br><center> <button class="button" name="DOOR" value="DOWN" type="submit">Zapri</button></center></center></form><br><br><br><br><div>  <canvas id="myChart"></canvas></div><script src="https://cdn.jsdelivr.net/npm/chart.js"></script><script>  const input = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];   # label will be replaced before sent as a response  const labels = [13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]; # label will be replaced before sent as a response      const data = {      labels: labels,      datasets: [{        label: 'Temperatures',        data: input,        fill: false,        borderColor: 'rgb(75, 192, 192)',        tension: 0.1      }]    };  const ctx = document.getElementById('myChart');  new Chart(ctx, {    type: 'line',    data: data ,        options: {      scales: {        y: {          beginAtZero: true        }      }    }  });</script></body></html><!DOCTYPE html><html></body> <body style="background-color:powderblue;"></body><head><meta name="viewport" content="width=device-width, initial-scale=1"><link rel="icon" href="data:,"><style>html { font-family: Helvetica; display: inline-block; margin: 0px auto; text-align: center;}.button { background-color: #4CAF50; border: 2px solid #000000;; color: white; padding: 15px 32px; text-align: center; text-decoration: none; display: inline-block; font-size: 16px; margin: 4px 2px; cursor: pointer; }.buttonRed { background-color: #d11d53; border: 2px solid #000000;; color: white; padding: 15px 32px; text-align: center; text-decoration: none; display: inline-block; font-size: 16px; margin: 4px 2px; cursor: pointer; }text-decoration: none; font-size: 30px; margin: 2px; cursor: pointer;}</style></head><body><center><h1>Garazna vrata</h1></center><br><br><form><center><center> <button class="button" name="DOOR" value="UP" type="submit">Odpri</button><br><br><center> <button class="buttonRed" name="DOOR" value="STOP" type="submit">Get Temp.</button><br><br><center> <button class="button" name="DOOR" value="DOWN" type="submit">Zapri</button></center></center></form><br><br><br><br><div>  <canvas id="myChart"></canvas></div><script src="https://cdn.jsdelivr.net/npm/chart.js"></script><script>  const input = ;   # label will be replaced before sent as a response  const labels = ; # label will be replaced before sent as a response      const data = {      labels: labels,      datasets: [{        label: 'Temperatures',        data: input,        fill: false,        borderColor: 'rgb(75, 192, 192)',        tension: 0.1      }]    };  const ctx = document.getElementById('myChart');  new Chart(ctx, {    type: 'line',    data: data ,        options: {      scales: {        y: {          beginAtZero: true        }      }    }  });</script></body></html>6 42 0   [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 22.8]6 43 0   [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 22.8, 22.8]6 44 0   [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 22.8, 22.8, 23.3]6 45 0   [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 22.8, 22.8, 23.3, 23.3]6 46 0   [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 22.8, 22.8, 23.3, 23.3, 23.3]6 47 0   [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 22.8, 22.8, 23.3, 23.3, 23.3, 23.3]

Statistics: Posted by California — Sun Jan 21, 2024 5:47 am



Viewing all articles
Browse latest Browse all 5251

Trending Articles