Highstocks 图表宽度未正确呈现
您好,我在使用 jquery 选项卡时遇到 highstocks 问题。
这是构造函数的代码。
Chart = new Highcharts.StockChart({
Chart = new Highcharts.StockChart({
chart: {
renderTo:
'Container',
alignticks:false
},
xAxis: { .......... },
yAxis: [{ ....... }],
series : [{ .......... }]
});
容器只有整个页面宽度的一半。
当页面加载到包含图形的选项卡时,其宽度将正确呈现。 但是,当页面首先加载到另一个选项卡时,其宽度跨越页面的整个宽度,与页面上的其他内容重叠。因此,必须刷新页面才能解决此问题。
有人有解决办法吗?
Hello I have a problem with highstocks when using jquery tabs.
this is the code for the constructor.
Chart = new Highcharts.StockChart({
Chart = new Highcharts.StockChart({
chart: {
renderTo:
'Container',
alignticks:false
},
xAxis: { .......... },
yAxis: [{ ....... }],
series : [{ .......... }]
});
The Container has only half the width of the whole page.
When the page is loaded to the tab containing the graph, then its width is rendered correctly.
But when the page is loaded first to another tab, then its width spans the whole width of the page, overlapping with other things on the page. So the page has to be refreshed in order to fix this.
Does anyone have a solution to this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您还可以触发 window.resize 事件
,并且 Highcharts 应该更新图表大小
You could also trigger the window.resize Event
And Highcharts should update the Chart size
Highcharts 将图表的宽度设置为包含元素的宽度。因此,如果包含元素被隐藏,它就无法获得宽度。
要解决此问题,您可以在初始化图表时设置宽度选项:
如果您无法将图表设置为正确的宽度,我使用此技巧来获取隐藏元素的宽度:
jQuery:获取 jQuery 中隐藏元素的高度
Highcharts sets the width of the chart to the width of the containing element. So if the containing element is hidden, it can't get a width.
To fix this you can set the width option when initializing your chart:
If you aren't able to set the chart to a proper width I've used this trick to be able to get the width of a hidden element:
jQuery: Get height of hidden element in jQuery
我知道您提出问题已经有一段时间了,但我遇到了类似的问题,每当图表位于默认情况下未激活的选项卡上时,我的图表就会以零宽度在客户端上呈现。这是因为,正如 @brent 所指出的,highcharts 使用父级的宽度,并且从 jQuery UI 1.9 开始,选项卡小部件使用
display: none
的内联样式来隐藏非活动选项卡。您应该使用图表所在选项卡的 activate 事件,而不是使用 jQuery 的文档就绪事件来初始化 highchart。这样做的另一个好处是,每次用户单击选项卡时都会执行时髦的图表动画。
代替:
使用:
I know this is a long while after you asked your question but I had a similar issue in that my charts were rendering on the client with zero width whenever the chart was on a tab that was not activated by default. This is because, as @brent indicated, highcharts uses the parent's width and, as of jQuery UI 1.9, the tab widget uses an inline style of
display: none
to hide the inactive tabs.Instead of using the document ready event of jQuery to initialize your highchart, you should instead use the activate event of your the tab your chart is on. This has the added benefit of doing the snazzy chart animation each time the user clicks the tab.
Instead of:
Use:
您可以使用百分比设置图表容器 div 的宽度。
像这样的东西应该有效。
You can set the width of the graph's container div with a percentage.
Something like this should work.
在样式表中,将类选择器
.ui-tabs .ui-tabs-hide
的规则替换为以下解决方案:jQuery UI - 选项卡
In your style sheet replace the rule for the class selector
.ui-tabs .ui-tabs-hide
withSolution taken from: jQuery UI - Tabs