Hello,
I’m trying to solve the following problem for a long time, trying out different approaches. However, none of them led me to a proper solution.
My goal is to visualize the periodically (e.g. every 1 ms) changing data on the same layout. This means I have 2 traces and the new updated data must not be added to the old one, but should exchange the old data points. I tried out Plotly,restyle(), Plotly.deleteTraces() Plotly.redraw() and even Plotly.newPlot(), but the data of the second trace is still appended to the old data. The data of the first trace is correct.
Please give me a hint, how to solve it. Thanks.
Here is my example code:
// Setup top plot
var TopPlotLayout = {
title: ‘Top View’,
showlegend: false,
xaxis: {
title: ‘Lateral distance[m]’,
range: [-30, 30],
dtick: 5,
gridcolor: ‘#bdbdbd’},
yaxis: {
title: ‘Longitudinal distance [m]’,
range: [-100, 100],
dtick: 10,
gridcolor: ‘#bdbdbd’}
};
Plotly.newPlot(‘TopPlot’, [ { x:[10000, 10000],y:[10000, 10000], mode: ‘markers’} ], TopPlotLayout);
function valueChanged(json_string)
{
// here extracting the data from JSON String etc....
var TopPlotData = {
x: AngleArray,
y: DistanceArray,
mode: 'markers',
marker: {size: 10, symbol: 'square-cross'}
};
var TopPlotRawData = {
x: AngleArrayRaw,
y: DistanceArrayRaw,
mode: 'markers',
marker: {size: 5, color: 'rgb(211, 104, 204)'}
};
var TopPlot = document.getElementById('TopPlot');
TopPlot.data[0] = TopPlotData; // replace by new data
TopPlot.data[1] = TopPlotRawData; // replace by new data
Plotly.redraw(TopPlot);
}