2016-07-26 108 views
0

我用javascript(jschart圖形庫)餅圖。當我用數組名稱設置餅圖數據的值時,餅圖不起作用。如果我使用靜態變量的話,我該如何解決這個問題?我如何設置餅圖數據的值與數組名稱jschart

這是靜態變量

function piechart() 
    { 
     var ctx = document.getElementById("myChart"); 
     var myChart = new Chart(ctx, { 
      type: 'pie', 
      data: { 
       labels: ["Galatasaray", "Fenerbahce", "Besiktas", "Diger"], 
       datasets: [{ 
        data: [12,4,19,3], 
        backgroundColor: [ 
       'rgba(255, 99, 132, 1)', 
       'rgba(54, 162, 235, 1)', 
       'rgba(255, 206, 86, 1)', 
       'rgba(75, 192, 192, 1)' 
      ] 
     }] 
      }, 
      options: { 
       responsive: true, 
       scales: { 
          beginAtZero: true      

       } 
      } 
     }); 
    } 

這是數組名

function piechart() 
{ 
    int dizim=[5,9,8,7]; 
    var ctx = document.getElementById("myChart"); 
    var myChart = new Chart(ctx, { 
     type: 'pie', 
     data: { 
      labels: ["Galatasaray", "Fenerbahce", "Besiktas", "Diger"], 
      datasets: [{ 
       data: dizim, 
       backgroundColor: [ 
      'rgba(255, 99, 132, 1)', 
      'rgba(54, 162, 235, 1)', 
      'rgba(255, 206, 86, 1)', 
      'rgba(75, 192, 192, 1)' 
     ] 
    }] 
     }, 
     options: { 
      responsive: true, 
      scales: { 
         beginAtZero: true      

      } 
     } 
    }); 
} 
+0

是int dizim一個錯字?它不應該是一個變種? – Joe

+0

JS中沒有'int'關鍵字;再加上即使這樣做,它可能會定義整數不是數組。 – Redu

回答

0

你可以做到通過更改int dizim=[5,9,8,7];工作var dizim=[5,9,8,7];

相關問題