使用Chart.js时图表无法正确呈现

时间:2014-04-24 21:30:54

标签: javascript charts

我正在使用Chart.js enter link description here来绘制折线图。问题在于其中一个数据集。当我用变量添加第三个数据集时,最大值变为8而不是128。

        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”)注释行实际上是该数组。我使用硬编码时可以,但是当我使用该变量时会出现问题。当我在第3个数据集中使用其他变量(如response.countSeen或response.countStart)时也可以

1 个答案:

答案 0 :(得分: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
    };
相关问题