[p5] I want to change the value of the gauge graphic in real time.
Is there an easy way to change that value?
link : p5.js Web Editor
ref : Gauge charts in JavaScript
source code
- index.html
<!DOCTYPE html>
<html lang="en">
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.4.1/p5.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.4.1/addons/p5.sound.min.js"></script>
<script src='https://cdn.plot.ly/plotly-2.14.0.min.js'></script>
<link rel="stylesheet" type="text/css" href="style.css">
<meta charset="utf-8" />
</head>
<body>
<main>
</main>
<script src="sketch.js"></script>
</body>
</html>
- sketch.js
var data = [
{
domain: { x: [0, 1], y: [0, 1] },
value: 450,
title: { text: "Speed" },
type: "indicator",
mode: "gauge+number+delta",
delta: { reference: 380 },
gauge: {
axis: { range: [null, 500] },
steps: [
{ range: [0, 250], color: "lightgray" },
{ range: [250, 400], color: "gray" }
],
threshold: {
line: { color: "red", width: 4 },
thickness: 0.75,
value: 490
}
}
}
];
var layout = { width: 400, height: 200, margin: { t: 0, b: 0 } };
function setup() {
createCanvas(400, 400);
let cnv;
let div_gauge = createDiv('');
div_gauge.id('gauge_1');
div_gauge.position(0,0);
background(0);
}
function draw() {
data.value=100; // --?
Plotly.newPlot('gauge_1', data, layout);
noLoop();
}
I want to change the value in the variable of ‘data’ in real time. Is there a way?
data.value=100; // ????