Responsive Highcharts not sizing correctly until window resize

前端 未结 12 1411
北荒
北荒 2021-01-30 16:06

I\'m using Highcharts within Zurb\'s Foundation framework for a class project. I have three charts within a section tab. One is within a 12-column div, the other two are on the

相关标签:
12条回答
  • 2021-01-30 16:34

    Just want to add another solution:

    $('.chart').highcharts(options, function(chart) {
      setTimeout(function() {
        chart.reflow();
      });
    });
    

    What it does is reflowing the chart the next frame after it has been rendered.

    0 讨论(0)
  • 2021-01-30 16:37

    Just use the chart.reflow() function

    0 讨论(0)
  • 2021-01-30 16:39

    Please take a look at these examples with responsive highcharts:

    http://jsbin.com/anuqav/1/edit

    http://jsfiddle.net/2gtpA/show/

    <div id="container" style="width:100%;margin: 0 auto"></div>
    
    0 讨论(0)
  • 2021-01-30 16:39

    You can use this code for the example

    var chart;
    $(function() {
      var newh = $("#container").height();
        $( window ).resize(function() {
        newh = $("#container").height();
        chart.redraw();
        chart.reflow();
      });
      chart = new Highcharts.Chart();
    })
    

    http://jsfiddle.net/Behseini/qheh4w0n/

    0 讨论(0)
  • 2021-01-30 16:40

    This might help:

    $(Highcharts.charts).each(function(i,chart){
        var height = chart.renderTo.clientHeight; 
        var width = chart.renderTo.clientWidth; 
        chart.setSize(width, height); 
      });
    
    0 讨论(0)
  • 2021-01-30 16:42

    Sort of an old topic now, but I had this issue with IE8. The current version of IE at the time of writing this is IE10, but I needed to make my site compatible with earlier versions. The solution that worked for me was a combination of above and other sites where people spoke about the solution they implemented. I went for a settimeout plus a resize and just executed for IE8, I hope this helps someone else like myself who tried to find a solution for a few hours.

    You may find just the script section is the only section you require.

    <!--[if IE 8]>
      <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
      <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
      <script>
        function timeout() {
            $(window).resize();
        }
        window.setTimeout(function() {
            timeout();
        },2000);
      </script>
      <style>
        .highcharts-container{width:100% !important; height:100% !important;}
      </style>
    <![endif]-->
    
    0 讨论(0)
提交回复
热议问题