我有一个Plotly JS Gauge的问题,我不能解决,我已经尝试了一千种方法来解决它。
如何实时、动态地使用Plotly JS Gauge?
我试过了,但它不起作用。;-(:
<script>
function rand() {
return Math.floor(Math.random() * (250 - 0) ) + 0;
}
var data = [
{
domain: { x: [0, 1], y: [0, 1] },
value: 0,
title: { text: "Speed" },
type: "indicator",
mode: "gauge+number"
}
];
var layout = { width: 600, height: 500, margin: { t: 0, b: 0 } };
Plotly.newPlot('myDiv', data, layout);
var cnt = 0;
var interval = setInterval(function() {
Plotly.extendTraces('myDiv', {value: [[rand()]]}, [0])
if(++cnt === 100) clearInterval(interval);
}, 300);
</script>发布于 2020-05-28 23:05:19
尝试使用Plotly.update()
function rand() {
return Math.floor(Math.random() * (250 - 0) ) + 0;
}
var data = [
{
domain: { x: [0, 1], y: [0, 1] },
value: 0,
title: { text: "Speed" },
type: "indicator",
mode: "gauge+number"
}
];
var layout = { width: 600, height: 500, margin: { t: 0, b: 0 } };
Plotly.newPlot('myDiv', data, layout);
var cnt = 0;
var interval = setInterval(function() {
Plotly.update('myDiv', {value: rand()}, {}, [0])
if(++cnt === 100) clearInterval(interval);
}, 800);<head>
<!-- Load plotly.js into the DOM -->
<script src='https://cdn.plot.ly/plotly-latest.min.js'></script>
</head>
<body>
<div id='myDiv'><!-- Plotly chart will be drawn inside this DIV --></div>
</body>
发布于 2021-10-30 20:54:46
如果未在设置中固定,则仪表范围将在更新时到处移动。在数据对象中使用属性'gauge‘来完成以下操作:
gauge: {axis:{range: [null, 100]}}例如,这会将其设置为最小值0和最大值100。
https://stackoverflow.com/questions/62061915
复制相似问题