Responsive doesn't fill the entire parent

Hello,

I am trying to figure out if plot.ly will work for our organization, so I am looking at a few charting libraries. My objective is to let the chart fill up the region of the parent. No whitespace at all. If it can’t do that, the chart size could be smaller to respect its aspect ratio.

I have already searched for existing solutions on how to make the responsive charts. In this example, my parent could be 400px by 250px. Right now it adds lots of whitespace, and for some reason, the labels are not part of the graph structure.

CodePen Attempt 1

From what I have read in the documentation my initial attemp was using the responsive config option:

image
https://codepen.io/mohamedhmansour/pen/OqxgKK?editors=0110

CodePen Attempt 2

Then I was trying autosize from the docs, same issue:

https://codepen.io/mohamedhmansour/pen/NJavwb?editors=0110

CodePen Attempt 3

Then I was reading more, and people started using the margin layout property, looks weird, all the labels are cut:

image
https://codepen.io/mohamedhmansour/pen/wOrqyW

CodePen Attempt 4

If I know the margins exactly, then I can set it this way:

https://codepen.io/mohamedhmansour/pen/KEXvBX

CodePen Attempt 5
Then there is automargin which sounds perfect, but that doesn’t work at all, doesn’t respect the parent size.


https://codepen.io/mohamedhmansour/pen/VRMzRw?editors=0110

Some questions:

  1. How could we perfectly fit the chart in the space allocated, no whitespace anywhere, without playing with margins?
  2. Is there a way to figure out the width of the labels on the left, top, right, and bottom, so we could apply the margins programmatically?

Thanks!

I am trying out highcharts as well, and for my attempt 1, it was working as expected.

CodePen Attempt 1 HighCharts
image

If there is a solution for above for plotly, I would give it a try again.

Here’s the “right” way: https://codepen.io/etpinard/pen/gEKNeb

It’s a little cumbersome right now unfortunately; we’re planning on polishing that up in the v2 release.

@etienne the chart gets out of borders of its parent

What I realised when I played with Plotly, is that it’s OK when it’s parent’s width is set in pixels. Once I set the width of a parent in %, it breaks. Edit: actually that is the case only when I try to render plotly plot in jsreport to a PDF.