简体   繁体   English

调整大小的图表渲染问题 <div> 容器

[英]Chart rendering issue with resizing <div> container

I have two question for chart rendering when its container is resized. 调整容器大小时,我有两个问题用于图表渲染。

First thing is, how to render chart correctly when its container is resized.. 首先 ,如何在调整容器大小时正确呈现图表。

ie Maximize / Restore problem, at its first rendering it works just fine, however when I restore the size of the window, the charts begin to overlay as its previous size. 即最大化/恢复问题,在它的第一次渲染它工作正常,但是当我恢复窗口的大小时,图表开始叠加为其先前的大小。 As you can see from the following pics: 从下面的图片可以看出: 在此输入图像描述在此输入图像描述

I know if you set a resize handler (and wait a small amount of time) to refresh the chart whenever the window is resized, the problem can be solved. 我知道如果你设置一个调整大小处理程序(并等待一小段时间),只要调整窗口大小,刷新图表就可以解决问题。 I am thinking whether there are some other approaches to let the chart flow to the right size without refreshing the chart every time. 我在想是否有其他方法让图表流动到正确的大小,而不是每次刷新图表。

The second thing is: If the charting area is in a <div> container, and the size of the container will change with a resize bar. 第二件事是:如果图表区域位于<div>容器中,并且容器的大小将随着调整大小条而改变。 I use the following code to get it work with the window resizing. 我使用以下代码来调整窗口大小。 But it won't work with a moving resize bar. 但它不适用于移动的调整大小栏。

$(window).resize(function () {
        setTimeout(function () {
            createChart(chartData);
        }, 300);
    });

Note : The grid component works just fine in any case and just the chart I am always having troubles. 注意 :网格组件在任何情况下都能正常工作,只是图表我总是遇到麻烦。 I am using HighCharts, kendoUI grid and both of them are rendered in jQueryUI portlets. 我正在使用HighCharts,kendoUI网格,它们都在jQueryUI portlet中呈现。

Any comments appreciated!This problem has taken me a long time.. 任何评论赞赏!这个问题花了我很长时间..

Update: Since I think my explanation of the issue is not clear enough, I added JSFiddle example for better understanding. 更新:由于我认为我对该问题的解释不够清楚,我添加了JSFiddle示例以便更好地理解。 Basically I want two things: 1. reflow the size of the chart to fit its container when window is resizing; 基本上我想要两件事:1。当窗口调整大小时,重新调整图表的大小以适合其容器; 2. reflow the size of chart to fit its container when the resize bar is moving. 2.当调整大小条移动时,重新调整图表的大小以适合其容器。

I am using plugins highcharts for charting, jQuery UI Layout for layout management in this example. 我在本例中使用插件highcharts进行图表处理, jQuery UI Layout用于布局管理。 For some other plugins I am using, please refer to here , I am not sure whether they have conflicts. 对于我正在使用的其他一些插件,请参考这里 ,我不确定他们是否有冲突。

Thanks! 谢谢!

I don't believe what you want can be accomplished without hooking the resize event and redrawing the chart. 如果不挂钩调整大小事件并重新绘制图表,我不相信你想要的东西。

To solve your "div" resize problem, look at something like this which allows you to bind the resize event to things other than the window (it your case your "container" div). 为了解决你的“格”调整问题,看像这个它允许你resize事件比窗口其他东西绑定(它的情况下,你的“容器” DIV)。

Here's a fiddle of it in action. 这是它在行动中的一个小提琴

Had a similar problem and solved it doing the following: 有类似的问题并解决了它做以下事情:

When defining the resizable div that will contain the higcharts chart: 定义包含higcharts图表的可调整大小的div时:

        $("#container").resizable({
            resize: function (event, ui) {
                var delay = 1000;
                setTimeout(function () {
                    $(window).resize();
                }, delay);
            }
        });

And inside the definition of the chart: 在图表的定义内:

           var chart = new Highcharts.Chart({
           .........
            $(window).resize(function() {
                chart.reflow();
           ..........
            });

So basically, you are resizing the window with a delay. 所以基本上,你是在延迟调整窗口大小。 Not very elegant, but works fine for me. 不是很优雅,但对我来说效果很好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM