我对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>
尝试使用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>