Reputation: 33
I am trying to make a chart that resizes automatically when I change the size of the window. Let's say I have this code from the documentation: https://jsfiddle.net/r3ckg7ep/1/
documentation link: https://developers.google.com/chart/interactive/docs/gallery/candlestickchart
code:
<html>
<head>
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript">
google.charts.load('current', {'packages':['corechart']});
google.charts.setOnLoadCallback(drawChart);
function drawChart() {
var data = google.visualization.arrayToDataTable([
['Mon', 20, 28, 38, 45],
['Tue', 31, 38, 55, 66],
['Wed', 50, 55, 77, 80],
['Thu', 77, 77, 66, 50],
['Fri', 68, 66, 22, 15]
// Treat first row as data as well.
], true);
var options = {
legend:'none'
};
var chart = new google.visualization.CandlestickChart(document.getElementById('chart_div'));
chart.draw(data, options);
}
</script>
</head>
<body>
<div id="chart_div" style="width: 900px; height: 500px;"></div>
</body>
</html>
How can it be accomplished?
Thank you
Upvotes: 2
Views: 61
Reputation: 61222
you have to re-draw the chart anytime there is a resize...
window.addEventListener('resize', function () {
chart.draw(data, options);
});
Upvotes: 2