Search code examples
chartsgoogle-visualizationbar-chart

How to control the width of a Google Chart when printing?


I have a Google Bar Chart. When viewing the chart on a narrow screen, like on a smartphone, if you print the page, the chart prints at the width of the device instead of at the width of the paper.

How can I make the chart print at the full width of the paper regardless of what device it's being viewed on?


Solution

  • the only way to resize a google chart is to re-draw it.

    as such, this would require listening for the window's 'beforeprint' event...

    window.addEventListener('beforeprint', (event) => {
      chart.clearChart();
      chart.draw();
    });
    

    and you could use 'afterprint' to reset...

    window.addEventListener('afterprint', (event) => {
      chart.clearChart();
      chart.draw();
    });