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

Cannot read property width of undefined

Hi,

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 (https://codepen.io/plotly/pen/wKpPvj), i.e.,

Plotly.plot(gd, …);

window.onresize = function() {
Plotly.Plots.resize(gd);
};

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,

Antonio

Something like:

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

  Plotly.Plots.resize(gd);
})

should work.

Great! Many thanks Étienne.

1 Like