簡體   English   中英

使用Chart.js時圖表無法正確呈現

[英]Chart not rendered properly while using Chart.js

我正在使用Chart.js 在此處輸入鏈接描述以繪制折線圖。 問題出在數據集之一。 當我添加帶有變量的第三個數據集時,最大值變為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”)注釋行實際上是該數組。 使用硬編碼時可以,但是使用該變量時會出現問題。 當我在第三個數據集上使用其他變量如response.countSeen或response.countStart時,也可以

我圍繞選項進行了工作,並根據需要進行渲染。 我創建了選項並在創建圖表時使用了它,然后它起作用了。

    // 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
    };

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM