Chart.js line chart is cut off at the top?

前端 未结 7 1498
死守一世寂寞
死守一世寂寞 2020-12-16 19:27

For some reasone all graphs are cut off at the highest value. How can i fix this? I can\'t use a fixed y-axis

7条回答
  •  借酒劲吻你
    2020-12-16 19:40

    I had my data values stored in array. So I set my max and min values like this:

    var _array = [1,3,2];
    var suggestedMin = Math.max.apply(Math,_array); // 3
    var suggestedMax = Math.min.apply(Math,_array); // 1
    

    And than you can set

        options: {
            scales: {
                yAxes: [{
                    ticks: {
                        beginAtZero: false,
                        suggestedMin: suggestedMin - 1,
                        suggestedMax: suggestedMax + 1,
                    }
                }]
            }
    
        }
    

    And it works, thank you.

提交回复
热议问题