# \[p5\] I want to change the value of the gauge graphic in real time

**URL:** https://discourse.processing.org/t/p5-i-want-to-change-the-value-of-the-gauge-graphic-in-real-time/38928
**Category:** Libraries
**Created:** [September 21, 2022, 11:06pm UTC](https://discourse.processing.org/t/p5-i-want-to-change-the-value-of-the-gauge-graphic-in-real-time/38928 "2022-09-21T23:06:48Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![GWAK](https://avatars.discourse-cdn.com/v4/letter/g/13edae/32.png) [@GWAK](https://discourse.processing.org/u/GWAK)
#### Post date: [September 21, 2022, 11:06pm UTC](https://discourse.processing.org/t/p5-i-want-to-change-the-value-of-the-gauge-graphic-in-real-time/38928/1 "2022-09-21T23:06:48Z")

</div>

[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](https://editor.p5js.org/gwakseongjong/sketches/Oz3xuCWQx)

ref : [Gauge charts in JavaScript](https://plotly.com/javascript/gauge-charts/)

source code

1. index.html

```auto
<!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>

```

1. sketch.js

```auto
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();
  
}

```

 ![fig](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/5/d/5d17c70f59c6e2b6081ae0c2bd09b92313ed4d2b.jpeg)

I want to change the value in the variable of ‘data’ in real time. Is there a way?

`data.value=100; // ????`

---

<div class="post-metadata">

### Author: ![svan](https://avatars.discourse-cdn.com/v4/letter/s/82dd89/32.png) [@svan](https://discourse.processing.org/u/svan)
#### Post date: [September 22, 2022, 2:53am UTC](https://discourse.processing.org/t/p5-i-want-to-change-the-value-of-the-gauge-graphic-in-real-time/38928/2 "2022-09-22T02:53:12Z")

</div>

**index.html**

```auto
<!DOCTYPE html>
<html lang="en">
  <head>
    <script src="https://cdn.plot.ly/plotly-2.14.0.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.4.1/p5.js">
    <script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.4.1/addons/p5.sound.min.js"> 
      </script>
  
    <link rel="stylesheet" type="text/css" href="style.css">
    <meta charset="utf-8" />

  </head>
  <body>
    <div id="gauge_1"><!-- Plotly chart will be drawn inside this DIV --></div>
    <script>
        Plotly.newPlot("gauge_1", {
            "data": [{
    domain: { x: [0, 1], y: [0, 1] },
    value: 0,
    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
      }
    }
  }],
            "layout": { width: 400, height: 400, margin: { t: 0, b: 0 }}
        })
    </script>
    <main>
    </main>
    <script src="sketch.js"></script>
  </body>
</html>

```

**sketch.js**

```auto
let slider;

function setup() { 
// gauge_1 created in index.html
  slider = createSlider(0, 500, 100);
  slider.position(10, 380);
}

function draw() {
  Plotly.update('gauge_1', {value: slider.value()}, {}, [0]);
}

```

Gauge is created in index.html and will reflect slider value.

 ![gauge](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/5/0/500aae7a2f2f306418720416893b1b6f9f0a530a.png)

---

<div class="post-metadata">

### Author: ![GWAK](https://avatars.discourse-cdn.com/v4/letter/g/13edae/32.png) [@GWAK](https://discourse.processing.org/u/GWAK)
#### Post date: [September 22, 2022, 8:06am UTC](https://discourse.processing.org/t/p5-i-want-to-change-the-value-of-the-gauge-graphic-in-real-time/38928/3 "2022-09-22T08:06:45Z")

</div>

@svan

`Plotly.update('gauge_1', {value: 50}, {}, [0]);`

thank you for the reply.

How did you know about the above command?

You can use it as above.  
Did you find it by looking at the .js file? Or do you mostly configure it as an update?  
If you know, please reply, thank you.

---

<div class="post-metadata">

### Author: ![svan](https://avatars.discourse-cdn.com/v4/letter/s/82dd89/32.png) [@svan](https://discourse.processing.org/u/svan)
#### Post date: [September 22, 2022, 1:45pm UTC](https://discourse.processing.org/t/p5-i-want-to-change-the-value-of-the-gauge-graphic-in-real-time/38928/4 "2022-09-22T13:45:55Z")

</div>

[https://stackoverflow.com/questions/62061915/plotly-gauge-dynamic](https://stackoverflow.com/questions/62061915/plotly-gauge-dynamic)

---

<div class="post-metadata">

### Author: ![GWAK](https://avatars.discourse-cdn.com/v4/letter/g/13edae/32.png) [@GWAK](https://discourse.processing.org/u/GWAK)
#### Post date: [September 22, 2022, 11:04pm UTC](https://discourse.processing.org/t/p5-i-want-to-change-the-value-of-the-gauge-graphic-in-real-time/38928/5 "2022-09-22T23:04:46Z")

</div>

@svan

Thanks for your kind reply.  
It’s been a big help.
