2017-04-30 7 views
-2

Ich mache ein Balkendiagramm und ich habe ein Problem mit Namen von Spalten. Ich habe auch versucht, Namen von x und yAx zu geben, aber hier war auch ein Problem. Das ist meine Daten aus Datenbank:Warum ist hier eine Nummer?

[{ "id": "1", "paliwo": "200", "przebieg": "150", "jedzenie": "0" }] 

enter image description here

Mein Code:

$(document).ready(function() { 
    $.ajax({ 
     url: "data.php", 
     method: "GET", 
     success: function(data) { 
      console.log(data); 
      var paliwo = []; 
      var przebieg = []; 
      for (var i in data) { 
       paliwo.push(data[i].paliwo); 
       przebieg.push(data[i].przebieg); 
      } 
      var chartdata = { 
       labels: paliwo, 
       przebieg, 
       datasets: [{ 
        label: 'Paliwo', 
        backgroundColor: 'rgba(200, 200, 200, 0.75)', 
        borderColor: 'rgba(200, 200, 200, 0.75)', 
        hoverBackgroundColor: 'rgba(200, 200, 200, 1)', 
        hoverBorderColor: 'rgba(200, 200, 200, 1)', 
        data: paliwo 
       }, { 
        label: 'Przebieg', 
        backgroundColor: 'rgba(200, 200, 200, 0.75)', 
        borderColor: 'rgba(200, 200, 200, 0.75)', 
        hoverBackgroundColor: 'rgba(200, 200, 200, 1)', 
        hoverBorderColor: 'rgba(200, 200, 200, 1)', 
        data: przebieg 
       }] 
      }; 
      var ctx = $("#mycanvas"); 
      var barGraph = new Chart(ctx, { 
       type: 'bar', 
       data: chartdata, 
       options: { 
        scales: { 
         yAxes: [{ 
          ticks: { 
           beginAtZero: true 
          } 
         }] 
        } 
       } 
      }); 
     }, 
     error: function(data) { 
      console.log(data); 
     } 
    }); 
}); 
+1

Was ist die Beziehung zu PHP? –

Antwort

0

ist dies, weil Sie labels:paliwo gegeben haben; Labels bezeichnet die x-Achse und paliwo enthält [200]