2016-07-28 80 views
0

我試圖繪製一個線條加上條形圖。 每當我試着畫出曲線圖(我試圖繪製折線圖中,同樣的錯誤),一條線的第一個點之前得出:折線圖在Chart.js中的第一個點之前繪製

Line Chart

這是我第一次嘗試chart.js之2.0,我繪製的其他圖表看起來很棒,除了這個...任何想法?

代碼:

function Data() { 
    $scope.barChartData = { 
     labels: $scope.mesesLabels, 
     datasets: [ 
      { 
       type: 'bar', 
       label: "" + myDate.getFullYear() - 1, 
       backgroundColor: "#5799c7", 
       data: $scope.infoAnoAnterior, 
       borderColor: 'white', 
       borderWidth: 2, 
      }, 
      { 
       type: 'bar', 
       label: "" + myDate.getFullYear(), 
       backgroundColor: "#ff7c40", 
       data: $scope.infoAnoAtual, 
      }, 
      { 
       type: 'line', 
       label: 'Média entre anos', 
       backgroundColor: "rgba(220,20,20,0)", 
       data: $scope.mediaEntreAnos, 
       borderColor: 'red', 
       borderWidth: 2, 
       pointBorderColor: 'black', 
       pointBackgroundColor: 'black' 
      }, ] 
    }; 
    drawChart(); 
} 

function drawChart(){ 
    var ctx = document.getElementById("base").getContext("2d"); 
    window.myBar = new Chart(ctx, { 
     type: 'bar', 
     data: $scope.barChartData, 
     options: { 
      responsive: true, 
      title: { 
       display: true, 
       text: 'Chart.js Combo Bar Line Chart' 
      }, 
      legend: { 
       display: true, 
       labels: { 
        fontColor: 'rgb(255, 99, 132)' 
       } 
      },     
     } 
    }); 
} 
+0

添加選項scaleBeginAtZero:true, –

+0

@NagaSaiA 沒有工作,發生同樣的事情... –

回答

0

爲了達到預期的結果,下面添加到選項

scaleStartValue: 0 
+0

也沒有工作...有任何其他建議?如果我的數據數組的第一個位置有一個空值,則線不會出現,但圖表不正確...感謝您的時間! –

1

難道你有問題的輸入值,而不是與圖表選項?即一些重複的值。

+0

只需雙重檢查,不要有任何重複 –

+0

然後您就必須分享您的JS代碼。 –

0

我在我的項目中添加了最新版本的chart.js(2.2.1),它工作,不知道爲什麼2.0沒有,但感謝您的時間!