最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Chart.js flickering - Stack Overflow

programmeradmin2浏览0评论

can anybody tell me why my chart.js chart is flickering? see this screencast video.

It looks slow in the video but it actually changes very fast. You will see in the console the height and width changes but I don't have any code in javascript that forces it to change.

And also it happens only sometimes depending on the size of the browser. Making the canvas small is just a temporary fix but it will still be reproducible when I resize the browser.

Any suggestions?

can anybody tell me why my chart.js chart is flickering? see this screencast video.

https://www.screencast.com/t/J8demDuX

It looks slow in the video but it actually changes very fast. You will see in the console the height and width changes but I don't have any code in javascript that forces it to change.

And also it happens only sometimes depending on the size of the browser. Making the canvas small is just a temporary fix but it will still be reproducible when I resize the browser.

Any suggestions?

Share Improve this question edited Jan 24, 2017 at 5:55 Vikrant 5,03618 gold badges51 silver badges74 bronze badges asked Jan 24, 2017 at 5:50 Voltaire John Secondes BitonVoltaire John Secondes Biton 7522 gold badges10 silver badges24 bronze badges 1
  • it's probably line 37 in your code ... but that's just a shot in the dark – Jaromanda X Commented Jan 24, 2017 at 5:58
Add a comment  | 

6 Answers 6

Reset to default 16

I had a similar problem with my chart. I discovered it happend when recreating the chart on the same canvas.

If you recreate your chart multiple times on the same canvas, try calling the

    .destroy();  

function on your chart before recreating it.

Hope this helps

I had a similar problem with my chart. I discovered it was happens when we don't set responsive to false. Please make sure to set it explicitly

In Options responsive: false

Its the issue with ChartJs version. Had this till on 2.7.0, Its resolved in latest version, its not flickering anymore.

https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.8.0/Chart.min.js

For me the solution was to wrap a component into React.memo

I had a similar problem with version 3.8.0. None of the other answers worked for me, but the solution was quite easy. I had a typing error in my css code.

If maintainAspectRatio is set to false, the height and width of the canvas element has to be correctly defined in the stylesheet.

The canvas element may try to get the height and width of the parent container, if the parent container doesn't have these properties (correctly) set, it trys to get these properties from the container the layer above and so on. And if there are no values available, the canvas starts to flicker.

Try to wrap the canvas in a div container and set the properties corrrectly, the canvas should stop flickering.

For Example:

<div id="canvasWrapper">
   <canvas id="canvasExample"></canvas>
</div>

#canvasWrapper{
   width: 100%;
   height: 40vh;
}

Here is the github Issue page of the plugin bug. You will find different solutions & workaround that will work for you. https://github.com/chartjs/Chart.js/issues/11005

发布评论

评论列表(0)

  1. 暂无评论