Charts.js sets canvas width/height to 0 and displays nothing

前端 未结 3 1547
眼角桃花
眼角桃花 2021-01-11 09:28

I am trying to use Charts.js to make the default line plot that they show in their example dynamically and put it in a div that I pop up on a user click. My code is like th

3条回答
  •  不思量自难忘°
    2021-01-11 10:00

    Your code works, with the exception of a typo. This line...

    this.chartCanvs.style.width = '900px';
    

    ...should be this:

    this.chartCanvas.style.width = '900px';
    //            ^ your code is missing this 'a'
    

    And here's a JS Fiddle with that typo fixed: http://jsfiddle.net/dun5dhne/

    Also, I strongly recommend opening your browser's developer console when you run into problems. This kind of thing is easy to catch in the console.

提交回复
热议问题