Resize charts on print.
See original GitHub issueI’m submitting a … (check one with “x”)
[ ] bug report => search github for a similar issue or PR before submitting
[X] feature request
[ ] support request => Please do not submit support request here
Current behavior When printing, the charts does not resize to fit paper.
Expected behavior Charts should be resized to fit paper.
Reproduction of the problem Use: https://swimlane.github.io/ngx-charts/#/ngx-charts/bar-vertical and enable “Fit to container”. Then press print. Depending on the size of the window, the graphs might not fit paper or appear partially behind other elements.
What is the motivation / use case for changing the behavior? Support printing (or export to PDF).
Issue Analytics
- State:
- Created 6 years ago
- Reactions:3
- Comments:14
Top Results From Across the Web
Move or resize a chart - Microsoft Support
To resize a chart, do one of the following: To change the size manually, click the chart, and then drag the sizing handles...
Read more >Resize chart.js canvas for printing - Stack Overflow
The solution is to render your chart to an image using the canvas.toDataURL() method when printing is invoked, then switch it back to...
Read more >Excel Chart sizes are different when printed and viewed on ...
Solution for where the Excel Chart sizes are different when printed (or even in print preview) as compared to what you see on...
Read more >Responsive Charts - Chart.js
js is unable to properly resize for the print layout. To work around this, you can pass an explicit size to .resize() then...
Read more >Resizing the chart for print - amCharts Help & Support - Zendesk
Usually browsers use different resolution when printing web pages. If you have charts that are wider than ~600-700 pixels, they will print as ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Here’s a solution that might help someone. I simply update the value of the [view] input with an arbitrary value that looks good on the page when I trigger the print dialog and then reset it after the dialog is closed.
I think I might be headed in the right direction in terms of a workaround:
In my app.component, I subscribe to beforeprint and afterprint events. Those events are forwarded to a service.
In the service, I resize the divs i wrapped around the charts (they all have the class “roc-chart-box”):
charts
is an array of ngx charts (e.g.BarVerticalComponent
) which are currently being displayed. Note how I disable animations and call update on each chart so it can resize quickly. To leave the chart a bit of time to resize, I await a promise which waits for 1 second. Also note that when resizing the chart wrapper div, all elements still have their old size - not the size they will have in the printed version.After the print, I revert the changes:
Problem with this solution is that charts are resized according to a fixed page width (800px in this case). This is the value that yielded the best results for me in Chrome. However, if I try other browsers or choose landscape mode when printing, the fixed width solution does not work anymore.
I post this in the hope of someone being able to improve this workaround.