Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JQuery Knob display number change

I'm using JQuery Knob to make some cool graphs and it's working perfectly. But I have one problem: I want to make the display number between the graph have a '%' symbol concatenated. but I just cant seem to make it work. Modifying the input through jquery wont do it, and I've tried reading into the code of the library but with no luck. Has any one else had this problem before?

like image 830
Guj Mil Avatar asked Sep 24 '12 04:09

Guj Mil


2 Answers

If you take a quick look at the github repo you'll see that there's a draw hook that's called everytime the canvas is drawn. If you implement that hook you should be able to add whatever you wish to the input. Here's a short example of the functionality you're looking for (to try it: http://jsfiddle.net/eAQA2/ ) and for future reference:

<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-1.8.2.min.js"></script>
<script src="https://raw.github.com/aterrien/jQuery-Knob/master/js/jquery.knob.js"></script>
<script>
$(function() {
    $(".dial").knob({
      'draw' : function () { 
        $(this.i).val(this.cv + '%')
      }
    })
})
</script>
</head>
<body>
<input type="text" class="dial" data-min="0" data-max="100">
</body>
</html>​
like image 174
Erik Avatar answered Oct 21 '22 16:10

Erik


As of version 1.2.7 there is now a format hook for performing tasks like this:

$(".dial").knob({
  'format' : function (value) {
     return value + '%';
  }
});
like image 36
Ben Holmes Avatar answered Oct 21 '22 17:10

Ben Holmes