当父容器隐藏时,Flot 图不会呈现
我遇到了一个问题,即浮点图无法在选项卡式界面中呈现,因为占位符 div 是带有“display: none”的 div 的子级。将显示轴,但不显示图形内容。
为了解决这个问题,我编写了下面的 javascript 函数作为绘图函数的包装器。对于其他人做类似的事情可能会有用。
function safePlot(placeholderDiv, data, options){
// Move the graph place holder to the hidden loader
// div to render
var parentContainer = placeholderDiv.parent();
$('#graphLoaderDiv').append(placeholderDiv);
// Render the graph
$.plot(placeholderDiv, data, options);
// Move the graph back to it's original parent
// container
parentContainer.append(placeholderDiv);
}
这是图形加载器 div 的 CSS,可以放置 页面上的任何位置。
#graphLoaderDiv{
visibility: hidden;
position: absolute;
top: 0px;
left: 0px;
width: 500px;
height: 150px;
}
I was having an issue where a flot graph would not render in a tabbed interface because the placeholder divs were children of divs with 'display: none'. The axes would be displayed, but no graph content.
I wrote the javascript function below as a wrapper for the plot function in order to solve this issue. It might be useful for others doing something similar.
function safePlot(placeholderDiv, data, options){
// Move the graph place holder to the hidden loader
// div to render
var parentContainer = placeholderDiv.parent();
$('#graphLoaderDiv').append(placeholderDiv);
// Render the graph
$.plot(placeholderDiv, data, options);
// Move the graph back to it's original parent
// container
parentContainer.append(placeholderDiv);
}
Here is the CSS for the graph loader div which can be placed
anywhere on the page.
#graphLoaderDiv{
visibility: hidden;
position: absolute;
top: 0px;
left: 0px;
width: 500px;
height: 150px;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
也许这是更好的解决方案。它可以用作
$.plot()
的替代品:然后只需调用
$.plot()
并将其更改为fplot( )
Perhaps this is better solution. It can be used as a drop in replacement for
$.plot()
:Then just take your call to
$.plot()
and change it tofplot()
唯一无需任何 CSS 技巧即可工作的方法是在 1 秒后加载绘图,如下所示:
或对于较旧的 jquery
上面的示例应用于 Bootstrap 标签的 Click 功能。但应该适用于任何隐藏的 div 或对象。
工作示例: http://topg.org/server-desteria-factions-级别-类-令牌-id388539
只需单击“玩家”选项卡,您就会看到上面的示例正在运行。
The only thing that works without any CSS trick is to load the plot 1 second after like this:
or for older jquery
The above example is applied to Bootstrap tags for Click funtion. But should work for any hidden div or object.
Working example: http://topg.org/server-desteria-factions-levels-classes-tokens-id388539
Just click the "Players" tab and you'll see the above example in action.
这是一个常见问题解答:
您的
#graphLoaderDiv
必须有宽度和高度,不幸的是,不可见的 div 没有它们。相反,使其可见,但将其左侧设置为-10000px
。然后,一旦您准备好显示它,只需将其左侧设置为 0px(或其他值)即可。This one is a FAQ:
Your
#graphLoaderDiv
must have a width and height, and unfortunately, invisible divs do not have them. Instead, make it visible, but set its left to-10000px
. Then once you are ready to show it, just set it's left to 0px (or whatever).好吧,我现在更好地理解你实际上在说什么......但我仍然认为你的答案太复杂了。我只是使用选项卡式界面进行了尝试,其中加载时图形位于隐藏选项卡中。这似乎对我来说效果很好。
http://jsfiddle.net/ryleyb/dB8UZ/
我没有
可见性:hidden
位在那里,但似乎没有必要...您也可以设置
visibility:hidden
,然后将选项卡代码更改为如下所示:但给出信息但这些似乎都不是特别必要的。
OK, I understand better now what you're actually saying... I still think your answer is too complicated though. I just tried this out using a tabbed interface where the graph is in a hidden tab when it's loaded. It seems to work fine for me.
http://jsfiddle.net/ryleyb/dB8UZ/
I didn't have the
visibility:hidden
bit in there, but it didn't seem necessary...You could also have
visibility:hidden
set and then change the tabs code to something like this:But given the information provided, none of that seems particularly necessary.
我知道这有点旧,但您也可以尝试使用 Flot 的调整大小插件。
http://benalman.com/projects/jquery-resize-plugin/
它是并不完美,因为有时您会看到可能缩小的非尺寸图形的闪现。此外,根据您使用的图表类型,某些格式和定位可能会关闭。
I know this is a bit old but you can also try using the Resize plugin for Flot.
http://benalman.com/projects/jquery-resize-plugin/
It is not perfect because you'll sometimes get a flash of the non-sized graph which may be shrunk. Also some formatting and positioning may be off depending on the type of graph that you are using.