Unexpected behaviour of Plotly.Update

I have problem with update function (or maybe with my approach).
Here is my situation:

  • I use scatter line plot with many traces (xaxis - timestamps, yaxis - integer values)
  • by every 1 minute app ask API for new data {x: [timestamp1, timestamp2], y: [value1, value2]}
  • after that I would like to update xaxis domain (with timestamps) and put new data (timestamp1, value1) into the end of existing plot data array.

I found out that it’s possible to use Update function, but I have problem, that after update, my old trace data dissapear and I can see only new data.
https://codepen.io/anon/pen/rgPgxx - uncoment line: //Plotly.update(‘myDiv’, update, {}, [0]) and then you can see it.
I thought that update “add” new data to existing trace without cleaning old data. I don’t know if it’s normal behavoiur or it’s a bug?

And second question: I also use Plotly.extendTraces function (xaxis: timestamps, yaxis: INT_VALUES). I’m showing only 30 min latest data for user and update plot by every 5 minutes. Can you tell if I have to take care about old data (older than 30 min.) by myself and clean somehow traces or Plotly.extendTraces do it automaticly?

Plotly.update will replace the old data with the new arrays, so the behavior you’re describing is the expected one.

You should try using extendTraces, see example here: https://plot.ly/javascript/plotlyjs-function-reference/#plotlyextendtraces

I think setting the 4th extendTraces argument should do the trick here.

1 Like

Thanks for your response. I thought that Plotly.update add traces not replace. It’s not clear in documentation.

I’ll try with mix functions: Plotly.relayout and Plotly.extendTraces:slight_smile: