Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
412 views
in Technique[技术] by (71.8m points)

javascript - dygraphs div not visible until browser Inspection window opened or browser resize

This has plagued me for a week, so I had to come to SO. (Forgive the URL, it's a dev server). http://www.stagestudio.com.ua/shutter_stat/wiev_base.php?cat=34

when I click on the photo the popup with linechart should appear but in fact the linechart is non visible. It can be visible only after resize the window or open browser inspection window.

How can I fix this?

This method dont work <script> var graph = new Dygraph(document.getElementById("graphPanel"), "temperatures.csv", { animatedZooms: true }); $(document).ready(function () { graph.resize(800, 500) }); </scrip>

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

This is a known issue that comes up from time to time. If a <div> is invisible, then it doesn't have any well-defined height or width. So rendering a chart in it doesn't do anything useful (it has zero height). dygraphs has no way of knowing that the chart <div> has become visible. This is really a gap in the DOM Events API. Other libraries like Google Maps have similar issues.

Workarounds are:

  • You can call .resize() without any parameters to force a redraw when the popup appears.
  • You can create the chart when the popup appears, rather than on page load. This way it the chart <div> will have a size when the chart is rendered.
  • You can assign the height and width explicitly, either in the dygraphs constructor or as styles on the chart <div>.

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...