2014-04-24 44 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 
    };