Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <title>Grafici SQL settimana</title>
- <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
- <script src="https://cdn.jsdelivr.net/npm/chart.js@2.9.4/dist/Chart.min.js"></script>
- <link rel="stylesheet" href="index.css">
- </head>
- <body>
- <div class="page-wrap">
- <div class="top">
- <div class="logo">
- <img src="https://imgur.com/DQ952ML.png" alt="Logo non disponibile" width="100%" height="auto">
- </div>
- </div>
- <div class="selezione">
- <div class="stazione"><label for="stazione">Inserisci il codice della stazione:</label>
- <input type="text" id="stazione" name="stazione" value="3C:61:05:1D:92:4C">
- </div>
- <div class="date"><label for="date">Inserisci la data:</label>
- <input type="date" id="date" name="date" value="2020-09-30">
- </div>
- <div class="tipo"><label for="tipo">Scegli l'arco temporale::</label>
- <select name="tipo" id="tipo">
- <option value="1">Giornaliero</option>
- <option value="2">Settimana min</option>
- <option value="3">Settimana avg</option>
- <option value="4">Settimana max</option>
- <option value="5">Mensile min</option>
- <option value="6">Mensile avg</option>
- <option value="7">Mensile max</option>
- <option value="8">Annuale min</option>
- <option value="9">Annuale avg</option>
- <option value="10">Annuale max</option>
- </select>
- </div>
- <div class="rap">
- <label for="rap">Tipo di grafico:</label>
- <select name="rap" id="rap">
- <option value="bar">Barre</option>
- <option value="line">Linee</option>
- </select>
- </div>
- <div class="applica"><input type="button" onclick="grafico()" value="Applica" /></div>
- </div>
- <div class="grafico">
- <canvas id="graficov" width="100%" height="50%"></canvas>
- </div>
- </div>
- <script>
- var graficov
- function grafico() {
- update();
- $.ajax({
- type: "POST",
- url: "data.php",
- data: {
- 'stazione': $("#stazione").val(),
- 'date': $("#date").val(),
- 'tipo': document.getElementById("tipo").value,
- },
- success: function(response) {
- console.log(response);
- var time = [];
- var timeg = [];
- var times = [];
- var timem = [];
- var timea = [];
- var temperatura = [];
- var umidita = [];
- var pressione = [];
- var altitudine = [];
- var lng = [];
- var lat = [];
- var noise = [];
- var co2 = [];
- var tvoc = [];
- var uv = [];
- for (var i in response) {
- time.push(response[i].orarilevazione);
- timem.push(response[i].anno + "-" + response[i].mese + "-" + response[i].giorno);
- timea.push(response[i].anno + "-" + response[i].mese);
- temperatura.push(response[i].temperatura);
- umidita.push(response[i].umidita);
- pressione.push(response[i].pressione);
- altitudine.push(response[i].altitudine);
- lng.push(response[i].lng);
- lat.push(response[i].lat);
- noise.push(response[i].noise);
- co2.push(response[i].co2);
- tvoc.push(response[i].tvoc);
- uv.push(response[i].uv);
- }
- var ctx = document.getElementById('graficov').getContext('2d');
- var rap = document.getElementById("rap").value;
- var test;
- graficov = new Chart(ctx, {
- type: rap,
- data: {
- datasets: [{
- label: 'temperatura',
- data: temperatura,
- backgroundColor: '#ff0000',
- fill: false,
- borderColor: '#ff0000',
- }, {
- label: 'umidita',
- data: umidita,
- backgroundColor: '#ff8000',
- fill: false,
- borderColor: '#ff8000',
- }, {
- label: 'pressione',
- data: pressione,
- backgroundColor: '#ffff00',
- fill: false,
- borderColor: '#ffff00',
- },
- {
- label: 'altitudine',
- data: altitudine,
- backgroundColor: '#80ff00',
- fill: false,
- borderColor: '#80ff00',
- }, {
- label: 'lng',
- data: lng,
- backgroundColor: '#00ff40',
- fill: false,
- borderColor: '#00ff40',
- }, {
- label: 'lat',
- data: lat,
- backgroundColor: '#00ffff',
- fill: false,
- borderColor: '#00ffff',
- },
- {
- label: 'noise',
- data: noise,
- backgroundColor: '#0000ff',
- fill: false,
- borderColor: '#0000ff',
- },
- {
- label: 'CO2',
- data: co2,
- backgroundColor: '#8000ff',
- fill: false,
- borderColor: '#8000ff',
- }, {
- label: 'TVOC',
- data: tvoc,
- backgroundColor: '#ff00bf',
- fill: false,
- borderColor: '#ff00bf',
- }, {
- label: 'UV',
- data: uv,
- backgroundColor: '#008744',
- fill: false,
- borderColor: '#008744',
- }
- ],
- labels: time
- },
- options: {
- legend: {
- labels: {
- fontColor: 'white',
- defaultFontSize: '10'
- }
- },
- scales: {
- yAxes: [{
- ticks: {
- fontColor: 'white',
- beginAtZero: true,
- fontSize: test
- }
- }],
- xAxes: [{
- ticks: {
- fontColor: 'white',
- beginAtZero: true,
- fontSize: test
- }
- }]
- }
- }
- });
- }
- })
- }
- function update() {
- if (graficov) {
- graficov.destroy();
- }
- }
- </script>
- </body>
- </html>
Add Comment
Please, Sign In to add comment