如果 x 轴初始化为
Plotly.newPlot('graph', [{
x: [Date.now()],
y: [],
mode: 'lines+markers',
marker: {color: 'pink', size: 8},
line: {width: 4}
}, {
x: [Date.now()],
y: [],
mode: 'lines+markers',
marker: {color: 'gray', size:8},
line: {width: 4}
}]);
功能
Plotly.extendTraces('graph', {
y: [[rand()], [rand()]],
x: [[Date.now()],[Date.now()]]
似乎按预期工作:
<p class="codepen" data-height="300" data-default-tab="html,result" data-slug-hash="mdQzyLE" data-user="fera0013" style="height: 300px; box-sizing: border-box; display: flex; align-items: center; justify-content: center; border: 2px solid; margin: 1em 0; padding: 1em;">
<span>See the Pen <a href="https://codepen.io/fera0013/pen/mdQzyLE">
extend multiple traces at once</a> by fera0013 (<a href="https://codepen.io/fera0013">@fera0013</a>)
on <a href="https://codepen.io">CodePen</a>.</span>
</p>
<script async src="https://cpwebassets.codepen.io/assets/embed/ei.js"></script>