迷你图渲染速度慢并且浏览器挂起
迷你图 非常适合制作小型内联图。但是,如果它们所在的容器是隐藏的,则不能简单地将它们绘制在幕后然后显示它们。您必须首先显示容器,然后调用 $.sparkline_display_visible
方法。
这没什么问题,只是如果你有很多图表的话,速度会很慢。我有 200 多张图表(最终会扩展到更多)需要渲染,渲染全部图表需要大约 4000 毫秒,从而导致浏览器挂起。有谁知道如何通过不挂起浏览器来加快此过程(值得怀疑)或提高感知性能?我尝试添加一个计时器,以便每个图表在渲染时一次显示一个,但是对于 200 多个图表,这仍然需要一段时间,而且效果有点分散用户的注意力。
谢谢
Sparklines are awesome for doing little inline graphs. However, if the container they are in is hidden, you can't simply draw them behind the scenes and then show them. You must first display the container and then call the $.sparkline_display_visible
method.
This is ok, except that it's really slow if you have a lot of graphs. I have a little over 200 graphs (and will eventually scale to more) to render and it takes around 4000ms to render them all, hanging the browser. Does anyone know how to either speed up this process (doubtful) or improve perceived performance by not hanging the browser? I tried to add a timer so each graph would show up one at a time while being rendered, but that still takes a while with 200+ graphs and the effect is a bit distracting to the user.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以让插件渲染加载时可见的图形,然后循环遍历隐藏的图形,并以 10 组为一组进行渲染。这样浏览器就不会挂起,并且会“预渲染”在您需要它们之前隐藏它们。
You could have the plugin render the graph for the ones that are visible on load then loop through the hidden ones and have it render those in groups of 10. Will make it so the browser doesn't hang and will "pre-render" the hidden ones before you need them.
不挂起浏览器渲染迷你图的解决方案是将其称为异步(使用偏移时间将事件设置为队列)。查看示例:
再见
,这里是测试页面
Solution for not hang browser with rendering sparklines is to call it async (with offset time setting events to queue). See sample:
Bye
here is the testing page
通过不同时执行所有这些操作,您可以轻松避免挂起浏览器。当图形进入视口时,异步渲染图形通常是可以的。
请参阅http://mleibman.github.com/SlickGrid/examples/ example10-async-post-render.html 作为一个工作示例。
You can easily avoid hanging the browser by not doing them all at the same time. It is usually OK to render graphs asynchronously when they come into the viewport.
See http://mleibman.github.com/SlickGrid/examples/example10-async-post-render.html for a working example.