view raw
mahesh mahesh - 5 months ago 43
Javascript Question

Dynamic update in Water bubble js

in the below code first time if i (any higher value)gave value = 29 the chart increases, second time if i give value less than 29 it doesn't work, level still stays in 29 but inside data has changed but not represented in chart. i cross checked in console. in waterbubble chart increase by value, but not decreasing by value. once higher value is given it is not reducing to lower value in chart

function s(){
var waterFill = document.getElementById("db01").value;
var fraction = waterFill / 100;
txt: ('' + waterFill).slice(-3).toString() + " %",
data: fraction,
animation: true
setInterval(function(){ s();// this will run after every 10 seconds
}, 10000);

<script src=""></script>
<script src=""></script>

<input id="db01" onkeyup="s()">
<div class=" col-lg-4">
<canvas id="demo-1"></canvas>


i solved it by changing in function NewValue(),

 function NewValue(){
 var data = document.getElementById("db01").value;
       if(data > .5){
            return Math.round(data*100);
        } else {
            return (data*100).toFixed(1);