2016-09-20 210 views
-1

我正在顯示一個餅圖和一個條形圖,但我的折線圖,具有相同類型的代碼,不顯示,我不知道爲什麼。這裏是我的代碼:爲什麼我的折線圖不顯示(Chart.JS)?

HTML

<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.1.3/Chart.js"></script> 
. . . 
<canvas id="forecastLineChart"></canvas> 

JQUERY

var lineChartData = { 
      labels: [ 
       "APPLES, GALA WAXF 138", "APPLES, GOLDEN DELICIOUS WAX 
100", "APPLES, GOLDEN DELICIOUS WAXF 113" 
      ], 
      datasets: [ 
       { 
        fillColor: "rgba(220,220,220,0.5)", 
        strokeColor: "rgba(220,220,220,0.8)", 
        highlightFill: "rgba(220,220,220,0.75)", 
        highlightStroke: "rgba(220,220,220,1)", 
        data: [49, 46, 153.86] 
       }, 
       { 
        fillColor: "rgba(151,187,205,0.5)", 
        strokeColor: "rgba(151,187,205,0.8)", 
        highlightFill: "rgba(151,187,205,0.75)", 
        highlightStroke: "rgba(151,187,205,1)", 
        data: [52, 40, 65.00] 
       }, 
       { 
        fillColor: "rgba(120,240,180,0.5)", 
        strokeColor: "rgba(120,240,180,0.8)", 
        highlightFill: "rgba(120,240,180,0.75)", 
        highlightStroke: "rgba(120,240,180,1)", 
        data: [42, 42, 227.70] 
       } 
      ] 
     } 
     var ctxLineChart = $("#forecastLineChart").get(0).getContext("2d"); 
     var forecastImpactLineChart = new Chart(ctxLineChart).Line(lineChartData); 

回答

2

的語法定義版本2中的圖表已經發生了一些變化。Fiddle

var forecastImpactLineChart = Chart.Line(ctxLineChart, { 
    data: lineChartData 
}); 

OR

var forecastImpactLineChart = new Chart(ctx, { 
    type: 'line', 
    data: lineChartData, 
    options: options 
}); 
1

錯字的代碼(缺少 「W」 來自新):

var forecastImpactLineChart = new Chart(ctxLineChart).Line(lineChartData); 
+0

只有在後,而不是在實際的代碼;我會修復帖子以更好地反映現實。 –