# 'TypeError: e is undefined' when using Plotly.relayout followed by Plotly.purge

**URL:** <https://community.plotly.com/t/typeerror-e-is-undefined-when-using-plotly-relayout-followed-by-plotly-purge/20442>\
**Category:** plotly.js\
**Created:** [March 4, 2019, 10:34pm UTC](https://community.plotly.com/t/typeerror-e-is-undefined-when-using-plotly-relayout-followed-by-plotly-purge/20442 "2019-03-04T22:34:20Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![shaelyn](https://avatars.discourse-cdn.com/v4/letter/s/edb3f5/32.png) [@shaelyn](https://community.plotly.com/u/shaelyn)\
**Post date:** [March 4, 2019, 10:34pm UTC](https://community.plotly.com/t/typeerror-e-is-undefined-when-using-plotly-relayout-followed-by-plotly-purge/20442/1 "2019-03-04T22:34:20Z")

</div>

This may be a user error, but I have no idea what I am doing wrong. I’m trying to return to the default x and y axis range before purging the plot so that when the plot is opened again, the x and y axis ranges correspond to the new trace being plotted. Currently, if I plot a trace, manually drag the axis ranges slightly off, and then purge the plot and try to plot another trace in  
the same div, the x and y axis ranges remain as they did after I manually changed them.

Here is the code:  
var update = {  
‘yaxis.rangemode’: “tozero”,  
‘xaxis.type’: “date”  
};  
var newlayout = {  
yaxis: {  
rangemode: “tozero”  
},  
xaxis: {  
type: “date”  
}  
};  
Plotly.relayout(‘plotly-TS’, newlayout);  
Plotly.purge(‘plotly-TS’);

This works as far as it does what I want it to do with resetting the axis ranges; however, I checked the console and I get  
this error “`TypeError: e is undefined”.  
I thought I was defining newlayout incorrectly and tried using update(as defined above) instead. When I do this, I get the same TypeError, and I do not get the desired behaviour with the plot range. The x and y axis ranges remain as they were when I manually drag them.

Am I doing something wrong? Or is there a different work around for my desired behaviour?

---

<div class="post-metadata">

**Author:** ![shaelyn](https://avatars.discourse-cdn.com/v4/letter/s/edb3f5/32.png) [@shaelyn](https://community.plotly.com/u/shaelyn)\
**Post date:** [March 5, 2019, 12:07am UTC](https://community.plotly.com/t/typeerror-e-is-undefined-when-using-plotly-relayout-followed-by-plotly-purge/20442/2 "2019-03-05T00:07:11Z")

</div>

It seems there were some timing issues. I put in a 10ms wait before purging and now I do not receive an error.

---

<div class="post-metadata">

**Author:** ![etienne](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/etienne/32/17_2.png) [@etienne](https://community.plotly.com/u/etienne)\
**Post date:** [March 5, 2019, 3:32pm UTC](https://community.plotly.com/t/typeerror-e-is-undefined-when-using-plotly-relayout-followed-by-plotly-purge/20442/3 "2019-03-05T15:32:43Z")

</div>

Hmm, strange. Could you provide a fully reproducible example in a codepen / jsFiddle to help us figure out what’s wrong here? Thank you.

---

<div class="post-metadata">

**Author:** ![shaelyn](https://avatars.discourse-cdn.com/v4/letter/s/edb3f5/32.png) [@shaelyn](https://community.plotly.com/u/shaelyn)\
**Post date:** [March 5, 2019, 5:34pm UTC](https://community.plotly.com/t/typeerror-e-is-undefined-when-using-plotly-relayout-followed-by-plotly-purge/20442/4 "2019-03-05T17:34:03Z")

</div>

Here’s a link to a fiddle: [https://jsfiddle.net/L9kch4zd/7/](https://jsfiddle.net/L9kch4zd/7/)  
After it loads, clicking Purge throws the TypeError.

---

<div class="post-metadata">

**Author:** ![shaelyn](https://avatars.discourse-cdn.com/v4/letter/s/edb3f5/32.png) [@shaelyn](https://community.plotly.com/u/shaelyn)\
**Post date:** [March 20, 2019, 4:28pm UTC](https://community.plotly.com/t/typeerror-e-is-undefined-when-using-plotly-relayout-followed-by-plotly-purge/20442/5 "2019-03-20T16:28:35Z")

</div>

@etienne Any updates/news regarding this?

---

<div class="post-metadata">

**Author:** ![etienne](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/etienne/32/17_2.png) [@etienne](https://community.plotly.com/u/etienne)\
**Post date:** [March 22, 2019, 8:08pm UTC](https://community.plotly.com/t/typeerror-e-is-undefined-when-using-plotly-relayout-followed-by-plotly-purge/20442/6 "2019-03-22T20:08:18Z")

</div>

Thanks for the jsFiddle!

Can I ask why you’re calling `Plotly.relayout` before `Plotly.purge` in your `Clone` handler?

---

<div class="post-metadata">

**Author:** ![shaelyn](https://avatars.discourse-cdn.com/v4/letter/s/edb3f5/32.png) [@shaelyn](https://community.plotly.com/u/shaelyn)\
**Post date:** [March 25, 2019, 4:26pm UTC](https://community.plotly.com/t/typeerror-e-is-undefined-when-using-plotly-relayout-followed-by-plotly-purge/20442/7 "2019-03-25T16:26:31Z")

</div>

Thanks for the response! I tried to explain in my original question, but I don’t think it was very clear.  
I want to return the layout of the plot to the ‘default’ before purging, because otherwise if I make a new plot in the same div, the layout is the same as the previous layout, even if it does not match the current graph.  
For example, in the jsFiddle:

1. After it loads, drag the y-axis down do you are looking at a different range (ie. 5-9).
2. Click ‘Purge’.
3. Click ‘RePlot’.  
The new plot should have the correct axis ranges. However, running the same steps above without the Plotly.relayout before the Plotly.purge, does not reset the axis. You can see this by commenting out Plotly.relayout in line 58 and following the same steps as above.
