question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ResponsiveContainer does not resize before printing

See original GitHub issue

Do you want to request a feature or report a bug?

Bug

What is the current behavior?

When printing is initiated, ResponsiveContainer re-uses the chart size from the window and does not scale properly regardless of the print specific outer container (green border) and ResponsiveContainer (red border) fixed dimensions.

If the current behavior is a bug, please provide the steps to reproduce

See screenshot screen shot 2017-12-26 at 20 51 27

What is the expected behavior?

ResponsiveContainer should resize to the specified fixed dimensions.

Which versions of Recharts, and which browser / OS are affected by this issue? Did this work in previous versions of Recharts?

1.0.0-beta.6, all browsers.

I understand printing may be out of scope of this project, but I am also hoping someone can offer a suggestion on how to solve this. After focusing on CSS-only solution which does not work since the chart is not resized, my next solution will be to listen to print events and conditionally set fixed dimensions although this solution is pretty messy and involved.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:12
  • Comments:11 (1 by maintainers)

github_iconTop GitHub Comments

10reactions
smashmiekcommented, Jul 26, 2018

I’m having the same issue. The ResponsiveContainer is not responding to width changes on print.

My current solution (only tested on Chrome so far) is to trigger element resize via @media print

// SCSS
.recharts-wrapper,
    .recharts-surface{
      @media print {
        width: calc(100%)!important;
      }
    }
2reactions
tuan-nguyen-vancommented, Jul 27, 2021

Screen Shot 2021-07-27 at 07 43 25 For me to fix this issue I added css to change the default behavior of recharts when printing. Need to fix recharts “Legend” tag as well. Tested on Chrome, Safari and Edge

@media print {
    //Recalculate width in print mode to fix the bug the graph isn't responsive when print.
    .recharts-wrapper, .recharts-surface, .recharts-legend-wrapper {
        width: 100%!important;
    }
    //Prevent recharts-legend-item have space between <svg> icon and <span> due to recalculate width: 100%
    //try width: fit-content not work on safari
    .recharts-legend-item > svg{
        width: auto!important;
        display: inline-block!important;
        right:inherit!important; /* align to left */
    }
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Recharts Responsive Container does not resize correctly in ...
I'm trying to create a custom collapsable legend for my data visualization app. It uses react and recharts.
Read more >
Recharts Responsive Container does not resize correctly in ...
So far I have found no downsides to this, but YRMV. It seems rather hacky but a viable fix is to set width...
Read more >
Responsive Charts - Chart.js
However, the resize won't happen automatically. To support resizing charts when printing, you need to hook the onbeforeprint (opens new window) ...
Read more >
Responsive design - Learn web development | MDN
Creating a non-resizable web page by setting a fixed width doesn't work either; that leads to scroll bars on narrow devices and too...
Read more >
Building responsive canvas apps - Power Apps - Microsoft Learn
Before you start using the responsive layouts, you need to do the following: ... Go to Settings > Display to disable Scale to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found