Black Lives Matter. Please consider donating to Black Girls Code today.

Cannot read property width of undefined


I’ve seen a couple of topics relating to this issue, but I have a question though.

I started seeing an error “cannot read property width of undefined”. It related to the resize function,

gd._redrawTimer = setTimeout(function() { // return if there is nothing to resize if(gd.layout.width && gd.layout.height) {

The placing of code follows your example about Responsive / Fluid Layout in plotly.js (, i.e.,

Plotly.plot(gd, …);

window.onresize = function() {

So, my question is how could I modify the flow, so that Plotly.Plots.resize(gd); is called after Plotly.plot has finished, so the the gd gets its layout.width properties defined.

Many thanks,


Something like:

Plotly.newPlot(gd, [/**/]).then(function() {


should work.

Great! Many thanks Étienne.

1 Like