Charts.js graph not scaling to canvas size

后端 未结 11 1185
隐瞒了意图╮
隐瞒了意图╮ 2020-12-08 09:45

I\'m trying to make a graph with Charts.js (current one is just a really simple example I\'m trying to get working, somewhat taken from the Chart.js documentation) and the g

11条回答
  •  無奈伤痛
    2020-12-08 10:24

    The width and height property that you set for the canvas only work if the Chartjs' responsive mode is false (which is true by default). Change your stats_tab.js to this and it will work.

        window.onload=function(){
            var ctx = document.getElementById("myChart").getContext("2d");
            var myChart = new Chart(ctx, {
                type: 'line',
                data: {
                    labels: [1,2,3,4,5,6,7,8,9,10],
                    datasets: [
                        {
                            label: "My First dataset",
                            data: [1,2,3,2,1,2,3,4,5,4]
                        }
                    ]
                },
                options: {
                    responsive: false
                }
            });
        }
    

提交回复
热议问题