How do I set the Meter/Gauge value from a variable?


« Back to message list

Enter your email address to get email updates on this topic. You can stop receiving updates by clicking the link in the update email messages.

Posted by Dean on 21st August 2017
I have built a meter and I am currently hard coding the value within the Javascript. I need to be able to set this value from a variable populated from a database. I have the code to get the value from the database, what's the easiest way to set the meter value to the variable?

Posted by Richard on 21st August 2017
Hi there,


Something like this (in PHP, ASP would be similar):

<script>
     var meter = new RGraph.Meter({
         id: 'cvs',
         min: 0,
         max: 100,
         value: <?php echo (int)$value ?>,
         options: {
         }
     }).draw();
</script>

So then, when you right-click the page in your browser and view the source, you should see something like this:

<script>
     var meter = new RGraph.Meter({
         id: 'cvs',
         min: 0,
         max: 100,
         value: 79,
         options: {
         }
     }).draw();
</script>








Richard
Posted by Dean on 21st August 2017
Thanks Richard, that worked great!

Add a reply




« Back to message list