Widget:Grafico

Da WikiLectio.

<script> (function(){

 var id  = "";
 var c   = document.getElementById("canvas_" + id);
 var msg = document.getElementById("msg_" + id);
 if (!c) { if (msg) msg.textContent = "Canvas non trovato (id="+id+")"; return; }
 if (typeof Chart === "undefined") { if (msg) msg.textContent = "Chart.js locale non caricato: controlla /resources/chart.umd.js"; return; }
 try {
   var labels = [0, 2, 4, 6, 8, 10];
   var data1  = [10, 8, 6, 4, 2, 0];   // Domanda
   var data2  = [0,  2, 4, 6, 8, 10];  // Offerta
   new Chart(c.getContext('2d'), {
     type: 'line',
     data: {
       labels: labels,
       datasets: [
         {
           label:'Domanda',
           data: data1,
           borderColor: '#d62728',      // rosso visibile
           backgroundColor: '#d62728',
           borderWidth: 2,
           pointRadius: 3,
           fill: false,
           tension: 0
         },
         {
           label:'Offerta',
           data: data2,
           borderColor: '#1f77b4',      // blu visibile
           backgroundColor: '#1f77b4',
           borderWidth: 2,
           pointRadius: 3,
           fill: false,
           tension: 0
         }
       ]
     },
     options: {
       responsive: false,
       maintainAspectRatio: false,
       plugins: {
         title: { display: true, text: 'Mercato affitti (demo)' },
         legend: { display: true }
       },
       scales: {
         x: {
           type: 'category',
           title: { display: true, text: 'Quantità' },
           grid: { display: true }
         },
         y: {
           title: { display: true, text: 'Prezzo' },
           min: 0,
           max: 12,
           grid: { display: true }
         }
       }
     }
   });
   if (msg) msg.textContent = "";
 } catch (e) {
   if (msg) msg.textContent = "Errore rendering: " + (e && e.message ? e.message : e);
   console.error("[Widget:Grafico] errore:", e);
 }

})(); </script>