Skip to content
Advertisement

remove the weird whitespace around the plotly chart (Javascript)

I’m using the plotly library (Javascript) for plotting piechart, I’m using the flexbox for the layout. There’s a huge whitespace on the right side of the chart as shown in image below: screenshot of issue

In the image above you could see whitespace on the right side of the pie chart. I’ve used the flexbox property : flex-grow to make use of all the space available. Why does flex-grow is not working here?

Codepen

index.html

JavaScript

style.css

JavaScript

chart.js

JavaScript

Advertisement

Answer

This happened because you set the width of the figure inside the first .r1 item. Flex box items are not meant to have a fixed width, even if it is computed from the flex box layout.

If you wait a little before calling make_pie() in the DOMContentLoaded handler, you can see the layout is as expected until you plot the figure.

To fix this you can add a relative width property to the flex items (especially those containing fixed-width elements), eg.

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement