pythonbook/fastapi_plotly/直接从前端得到数据.html

47 lines
1.1 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script src="./plotly-latest.min.js"></script>
<style>
/* 设置html和body的高度和宽度为100%,并移除边距和填充 */
html, body {
height: 100%;
width: 100%;
margin: 0;
padding: 0;
}
/* 设置图表div的大小为视口的100% */
#plot {
height: 100vh;
width: 100vw;
}
</style>
</head>
<body>
<div id="plot"></div>
<script>
var trace = {
x: [], y: [], z: [],
mode: 'markers',
type: 'scatter3d'
};
var layout = {
title: '3D Scatter Plot'
};
Plotly.newPlot('plot', [trace], layout);
setInterval(function(){
// 模拟生成随机数据
var x = Math.random();
var y = Math.random();
var z = Math.random();
// 使用模拟的数据更新图表
Plotly.extendTraces('plot', { x: [[x]], y: [[y]], z: [[z]] }, [0]);
}, 1000); // 更新频率为每秒
</script>
</body>
</html>