I am trying to create a scatter diagram that can be updated (data replaced).
let init = [{
x: [1, 3, 4, 200,3],
y: [16, 0, 11, 100,99],
mode: 'lines',
type: 'scatter'
}]
let layout = {
title: 'testing', // updates the title
'xaxis.range': [0, 500], // updates the xaxis range
'yaxis.range': [-3,3] // updates the end of the yaxis range
};
Plotly.newPlot("chart_test", init, 0);
Plotly.relayout("chart_test", layout,0); //layout applied later, because of auto change.
Works fine, plots correctly. The problem is at changing the data:
let style = {
type:'scatter',
mode: 'marker'
x:[1,5,6,70],
y:[3,4,2,1]
}
Plotly.restyle("chart_test", style);
It will change the mode (from line to marker in this example), but the x and y data will not change.
For now, I resort to using Plotly.newPlot() for updating, but that is not efficient.
What am I doing wrong when providing new datapoints? Could I use Plotly.react() and have the same result as Plotly.restyle()?
solved:
let style = {
type:'scatter',
mode: 'marker'
x:[[1,5,6,70]], // EDITED <--- array of traces data
y:[[3,4,2,1]] // EDITED <--- array of traces data
}
Plotly.restyle("chart_test", style);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.