I have a Google pie chart which works fine but it is not responsive, how to make it responsive?
Here is a <div>
on which i'm forming piechart.
<div id="piechart" style="width: 900px; height: 500px;"></div>
Here is a fiddle of my code.
First, we import react-google-charts and get the Chart property. Next, we create a data variable that will house the data to be displayed on the pie chart. The pie chart is highly customizable; for a more complex chart, you only need to update the data to the array.
Here is a solution, using throttledresize.js.
div id="chart_div"
in a parent div
<div id="chart_wrap">
<div id="chart_div"></div>
</div>
#chart_wrap {
position: relative;
padding-bottom: 100%;
height: 0;
overflow:hidden;
}
#chart_div {
position: absolute;
top: 0;
left: 0;
width:100%;
height:100%;
}
Note: Adapt the CSS to your needs.
$(window).on("throttledresize", function (event) {
var options = {
width: '100%',
height: '100%'
};
var data = google.visualization.arrayToDataTable([]);
drawChart(data, options);
});
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