extendTraces 使用时间戳作为 x 值

问题描述 投票:0回答:1
javascript plotly plotly.js
1个回答
0
投票

如果 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>

© www.soinside.com 2019 - 2024. All rights reserved.