简体   繁体   English

Highchart - 调整窗口大小后重绘图表

[英]Highchart - Redraw Chart after Window is resized

on my webpage is a chart drawn with Highchart. 在我的网页上是用Highchart绘制的图表。 Now, if i resize my whole window i want this chart to adjusts its size (especially the width). 现在,如果我调整整个窗口的大小,我希望此图表调整其大小(尤其是宽度)。 The Code looks similar to this: 该守则看起来类似于:

window.onresize=function(){resized();}

function resized()
{
   $("#container").highcharts().redraw();
}

If I overwrite the redraw event (with something like "alert("resized");") I will get a result so the method should be called - but the chart doesn't changes its size. 如果我覆盖重绘事件(使用类似“alert(”resized“);”),我将得到一个结果,因此应该调用该方法 - 但图表不会改变其大小。 I also tried to set the charts size manually with 我还尝试手动设置图表大小

$("#container").highcharts().setSize(width, height, false);

But both ways didn't work. 但两种方式都不起作用。 Is there any other solution? 还有其他解决方案吗?

Did you try code in this manner so it will automatically handle chart resizing on window resize. 您是否以这种方式尝试代码,因此它会自动处理窗口调整大小的图表大小调整。

 // create the chart
var chart = Highcharts.chart('container', {
chart: {
    events: {
        redraw: function () {
            var label = this.renderer.label('The chart was just redrawn', 100, 120)
                .attr({
                    fill: Highcharts.getOptions().colors[0],
                    padding: 10,
                    r: 5,
                    zIndex: 8
                })
                .css({
                    color: '#FFFFFF'
                })
                .add();

            setTimeout(function () {
                label.fadeOut();
            }, 1000);
        }
    }
},
xAxis: {
    categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
},

series: [{
    data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4]
}]
});

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

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