$(document).ready(()=>{
  const today = new Date().toISOString().slice(0, 10);
  //var layout = { title: 'Download Chart as SVG instead of PNG', showlegend: false };
  $.get('/api/pogoda',(d,status)=>{
    Plotly.newPlot("temp", [ 
      {
        x: d.time, 
        y: d.temp, 
        type:"bar", 
        marker: { color: "rgba(122, 29, 29, 0.6)" } 
      } 
    ], {
      title: { text: "Temperatura" },
      xaxis: {
        title: { text: today },
        tickformat: '%H:%M',
        dtick: 60 * 60 * 1000
      },
      yaxis: {
        title: { text: 'Temperatura (°C)' }
      }
    } );

    Plotly.newPlot("hum", [ 
      {
        x:d.time, 
        y:d.hum, 
        type:"bar", 
          marker: { color:"rgba(22, 76, 117, 0.6)" 
          } 
      } 
    ], {
      title: { text: "Wilgotność" },
      xaxis: {
        title: { text: today },
        tickformat: '%H:%M',
        dtick: 60 * 60 * 1000
      },
      yaxis: {
        title: { text: 'Wilgotność (%)' }
      }

    } );

    Plotly.newPlot("wind", [ 
      {
        x:d.time, 
        y:d.wind, 
        type:"bar", 
          marker: { color:"rgba(0, 255, 76, 0.6)" 
          } 
      } 
    ], {
      title: { text: "Wiatr" },
      xaxis: {
        title: { text: today },
        tickformat: '%H:%M',
        dtick: 60 * 60 * 1000
      },
      yaxis: {
        title: { text: 'Wiatr (m/s)' }
      }

    } );

  });
  $("#date").text(today);
});
 