I’m building a webapp where some data is fed in real time on a chart from a Database.
However, i’m facing an issue and i can’t find a way to fix it: when i load a new datapoint which is distant (in terms of time) from the last datapoint, my chart gets bugged and it won’t load data correctly (see my screenshot)
@Dev20 What happens when you zoom in on the x-axis near those narrow vertical lines? It looks to me that the points are probably being ploted correctly but the scale is off because the large distance between the actual data represents > 99% of the time shown in the graph.
If that is the case, you could try setting the xaxis range manually to only show the latest data or you could separate the data into meaningful chunks and let the user choose a chunk using a Dropdown menu.
Hey! Thanks for your answer! Yes, indeed, if i zoom a lot, the data seems to be charted normally. The problem is that i had this problem with a bar chart too. I don’t know why, but i expected my chart to ‘connect’ to the last datapoint and start charting again from there, instead of having that huge jump. I think the issue could be somehow related to the timestamp on the X-axis. I’ll try to set the xaxis range manually, as you said
@Dev20 With bar graphs, you can set layout = go.Layout(xaxis=dict(type='category')) to prevent all of that space from being ploted in between the importand bits and I just realized now that you can do the same thing with a scatter trace. So I think that would solve your issue
@Dev20, it looks like plotly is still making the xaxis as a date. Did you make sure to add layout=layout to the call to go.Figure (i.e go.Figure(data=[trace], layout=layout)). Can you post your entire code (or a smaller reproducible example)?
@Dev20, yeah it looks like that last line is the problem. The layout is being defined but not included in the chart. Changing that line to return Figure(data=[trace], layout=layout) should fix things.