2014-04-24 48 views
0

我使用Chart.js enter link description here繪製折線圖。問題在於其中一個數據集。當我用變量添加第三個數據集時,最大值變爲8而不是128。使用Chart.js時圖表顯示不正確

 datasets : [ 
        { 
         fillColor : "#1abc9c", 
         strokeColor : "#1abc9c", 
         pointColor : "#1abc9c", 
         pointStrokeColor : "#fff", 
         data : response.countStart 
        }, 
        { 
         fillColor : "#3498db", 
         strokeColor : "#3498db", 
         pointColor : "#3498db", 
         pointStrokeColor : "#fff", 
         data : response.countSeen 
        }, 
        { 
         fillColor : "#e67e22", 
         strokeColor : "#e67e22", 
         pointColor : "#e67e22", 
         pointStrokeColor : "#fff", 
         data: response.countClicked 
         //data : [0, 0, 10, 1, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 8, 0, 0, 6, 11, 15, 20, 2] 
        } 
       ] 

我有三個數據集,我用AJAX獲取它們,並在收到響應時創建圖表。將最後一個數據集添加到數組時,會出現問題。 (「response.countClicked」)註釋行實際上就是該數組。當我使用硬編碼時可以,但使用該變量時會出現問題。當我在第三個數據集上使用response.countSeen或response.countStart等其他變量時也是可以的

回答

0

我對選項進行了解決,並按照我的意願進行了渲染。我創建了選項並在創建圖表時使用了它,並且它工作正常。

// getting the most possible array that contains the max value 
    var max = Math.max.apply(Math, response.countSeen); 
    var steps = max/10; 
    var options = { 
     scaleOverride: true, 
     scaleSteps: steps, 
     scaleStepWidth: 10, 
     scaleStartValue: 0 
    };