简体   繁体   English

Google Barchart不会在我的HTML中动态调整大小

[英]Google Barchart doesn't dynamicly resize in my HTML

I have implemented a Google barchart into m dynamic webpage (width is 100%) but when I resize my browserwindow, the barchart remains as big as it was. 我已经在动态网页(宽度为100%)中实现了Google条形图,但是当我调整浏览器窗口的大小时,条形图仍然保持原样。 It only changes size when I then refresh my browser. 仅当我随后刷新浏览器时,它才会更改大小。

EDIT: THIS CODE WORKS //Add this 编辑:此代码有效//添加此

<script>
    $(document).ready(function () {

$( window ).resize(function() {
    $("#chart_div").css("width", $("div.cnt").width());
    drawChart();
});
});

</script>
<script type="text/javascript">
  google.load("visualization", "1", {packages:["corechart"]});
  google.setOnLoadCallback(drawChart);
  function drawChart() {
    var data = google.visualization.arrayToDataTable([
      ['Politicus', 'Vragen', 'Beantwoord'],
      ['Bart De Wever',  30,      20,],
      ['Filip De Winter',  25,      10],
      ['Maggie De Block',  20,       15],

    ]);

    var options = {
      title: '',
      legend: {position: 'top' },
      vAxis: {title: 'Aantal',  titleTextStyle: {color: 'red'}},
      orientation: 'horizontal',
    };

    var chart = new google.visualization.BarChart(document.getElementById('chart_div'));
    chart.draw(data, options);
  }
</script>

This is the div that should resize when i change the browserwindow 这是我更改浏览器窗口时应调整大小的div

<div class="cnt"><div id="chart_div" style="width: 100%; height: 400px;"></div>

Thanks 谢谢

FOR your problem refer this link https://groups.google.com/forum/#!msg/google-chart-api/v3HSyEqGaw8/4aH083z4sCIJ 对于您的问题,请参考此链接https://groups.google.com/forum/#!msg/google-chart-api/v3HSyEqGaw8/4aH083z4sCIJ

OR for general u can use resize event 或一般来说,您可以使用调整大小事件
The resize event is sent to the window element when the size of the browser window changes so USE it example is 当浏览器窗口的大小更改时,将resize事件发送到window元素,因此使用USE it example是

$( window ).resize(function() {
  $( "body" ).prepend( "<div>" + $( window ).width() + "</div>" );
});

for more information https://api.jquery.com/resize/ 有关更多信息https://api.jquery.com/resize/

Example http://jsfiddle.net/arjun_chaudhary/y9Rzu/ 示例http://jsfiddle.net/arjun_chaudhary/y9Rzu/

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

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