Please help me how to automatically re-size the Google chart when the windows re-size too.
Here is some code:
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load("visualization", "1", {packages:["corechart"]});
google.setOnLoadCallback(drawChart);
function drawChart() {
var data = google.visualization.arrayToDataTable([
['Day', 'Open ticket', 'Closed ticket'],
['Day 1', 10, 400],
['Day 2', 170, 460],
['Day 3', 60, 1120],
['Day 4', 30, 540],
]);
var options = {
title: 'DAILY GRAPH',
hAxis: {title: 'NOVEMBER', titleTextStyle: {color: '#333'}},
vAxis: {minValue: 0}
};
var chart = new google.visualization.LineChart(document.getElementById('chart_div'));
chart.draw(data, options);
}
</script>
Here's one way:
Add this event handler:
window.onresize = drawChart;
Then base the chart width and height on a percentage of the window's width and height:
var width = .4 * window.innerHeight;
var height = .4 * window.innerWidth;
var options = {
title: 'DAILY GRAPH',
width: width,
height: height,
hAxis: { title: 'NOVEMBER', titleTextStyle: { color: '#333' } },
vAxis: { minValue: 0 }
};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With