Chart.js的最大值和最小值出现问题[折线图]

时间:2017-09-15 10:02:28

标签: javascript canvas charts chart.js

我想用一条线创建一个小图。 当我第一次创建时,我没有看到起点和终点之间有很大的不同。所以我尝试将最小值设置为与min-val相同。而且作为我的yAxes上的最大值的最大值。

这是我的代码:

var generateNormalChart = function (dataForNormalGraph, randomColors, theLongNameOfTheCoin,currency,exchange,minVal,maxVal,stepsize) {
    var ctx = document.getElementById('normalChartGraph' + theLongNameOfTheCoin + currency + exchange).getContext('2d');
    var normalChart = new Chart(ctx, {
    type: 'line',
    data: {
        datasets: [{
            fill: false,
            borderColor: randomColors,
            data: dataForNormalGraph,
            pointRadius: 1,
            borderWidth: 2
        }]
    },
    options: {
        legend: {
            display: false
        },
        scales: {
            xAxes: [{
                display: false

            }],
            yAxes:[{
                display: false,
                ticks: {
                    max: maxVal,
                    min: minVal
                    // stepSize: stepsize
                }
            }]
        }
    }
});

};

我使用的数据示例:

这是maxVal:0.0000505

这是minVal:0.00005483

这是dataForNormalGraph:

0:0.00005162
1:0.00005124
2:0.0000505
3:0.00005056
4:0.00005089
5:0.0000509
6:0.00005102
7:0.00005067
8:0.00005087
9:0.00005156
10:0.00005173
11:0.00005191
12:0.00005363
13:0.00005276
14:0.00005309
15:0.00005297
16:0.00005231
17:0.00005243
18:0.00005252
19:0.00005271
20:0.00005326
21:0.00005408
22:0.00005483
23:0.00005376
24:0.00005365

就像你可以看到我评论了步数值。 我甚至通过计算((the max and min val) / 25)1.7320000000000004e-7

之间的差异来尝试使用它

我也不想看到标签和Axes值,因为它占用了很多空间。

我有2张照片,你可以看到他忽略了最大和最小值:

A photo with the values on the yAxes

我想要的是然后使用正确的最大值和最小值

what I want but then with the right max and min values

1 个答案:

答案 0 :(得分:0)

我忘了给出yAxes的价值,这些价值并没有带来好的图表。 我唯一需要做的就是添加

            labels: nameOfTheCoins,

所以yAxes有一个值