简体   繁体   English

响应多个Google图表

[英]Responsive more than one google charts

I'm using google charts in my website, and since yesterday i'm searching about a solution to make my charts responsive, I found one in stackoverflow : 我在网站上使用Google图表,从昨天开始,我一直在寻找一种使图表具有响应能力的解决方案,所以我在stackoverflow中找到了一个:

<script>
function resize () {
    // change dimensions if necessary
    chart.draw(dataTable1, options);
    chart.draw(dataTable2, options);
    chart.draw(dataTable3, options);
}
if (window.addEventListener) {
    window.addEventListener('resize', resize);
}
else {
    window.attachEvent('onresize', resize);
}
</script>

But the probleme is when i use more than one chart only one become responsive, The example is here : http://jsfiddle.net/faissal_aboullait/5f92veyy/ 但是问题是当我使用多个图表时,只有一个图表会响应,示例在此处: http : //jsfiddle.net/faissal_aboullait/5f92veyy/

The problem is that you're using the same var chart. 问题是您使用的是相同的无功图。

And of course using it all over again, the chart variable will keep a reference of the 3rd chart. 当然,要再次使用它,chart变量将保留第三个图表的引用。

Declare a different variable for every chart like this: 为每个图表声明一个不同的变量,如下所示:

var reservationChart; 
//............
reservationChart = new google.visualization.ColumnChart(document.getElementById('chart_reservations'));
reservationChart.draw(dataTable1, options);   

And then the resize function will look like this: 然后,调整大小函数将如下所示:

function resize () {
        // change dimensions if necessary
        reservationChart.draw(dataTable1, options);
        clientsChart.draw(dataTable2, options);
        deprecChart.draw(dataTable3, options);
    }

An updated fiddle here: http://jsfiddle.net/d8vaxuug/ 更新的小提琴在这里: http : //jsfiddle.net/d8vaxuug/

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

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