javascript - How to get a shifting Plotly plot with JavaScript?
问题描述
I am trying to create a flowing Plotly plot. However, I am not sure which Plotly parameters to use in order to achieve the result in the example image at the very bottom.
My Plotly is here: RandomSignalFlow
The HTML:
<head>
<script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
</head>
<body>
<div id="graph"></div>
</body>
The JS:
function rand() {
return Math.random();
}
Plotly.plot('graph', [{
y: [1,2,3].map(rand),
mode: 'lines',
line: {color: '#80CAF6'}
}]);
var cnt = 0;
var interval = setInterval(function() {
Plotly.extendTraces('graph', {
y: [[rand()]]
}, [0])
if(cnt === 100) clearInterval(interval);
}, 300);
So this would create the data flow, but the plot will be constantly compressing horizontally as the data flows in. I am after a tracking
behaviour (as in the image bellow).
I tried using .shift()
to crop the data's X
and Y
components but that did not work for some reason.
The project associated with the image is here.
解决方案
推荐阅读
- python - 在 Asyncio Web Scraping Application 中放置 BeautifulSoup 代码的位置
- google-sheets - 查询一列是否匹配,然后直接返回左侧列中的数据数组
- react-native - 如何使用 Moment 在 React-Native 中将 Firestore Timestamp UTC 转换为 UTC+1?
- java - 如何向用户显示电影列表,让他选择电影并将电影保存在表格中?
- swift - Thread1 -[Subject addTasksObject:]:无法识别的选择器发送到实例 0x60000293cb00'
- python - 将 Twilio 帐户添加到 whatsapp 组
- python - Python 提取两个时间戳之间的 JSON 对象模式
- javascript - 递增和递减 Firebase Ionic 5
- javascript - useState 如何遍历数组
- javascript - 变量何时相互分配的规则