jQuery-Knob icon indicating copy to clipboard operation
jQuery-Knob copied to clipboard

Adding percentage next to the number?

Open dev1212 opened this issue 10 years ago • 13 comments

Is it possible to also reflect in percentage like 10%, 20%?

dev1212 avatar Apr 05 '14 13:04 dev1212

why not using format?

you can find the feature here and it's in the current version.

balexandre avatar Apr 05 '14 15:04 balexandre

Hi tried this with format but.. it doesnt show the percentage initially and show NaN initially

$(function() {

$(".dial").knob();

            $('.dial')

.trigger(

    'configure',

    {

    "min":0,

    "max":100,

    parse: function (v) {return parseInt(v);},       

                            format: function (v) {return v + "%";}

    }

);

});

dev1212 avatar Apr 08 '14 22:04 dev1212

what i see is that you dynamically alter configuration with trigger('configure') function. in such case, follow this statement with trigger('change') in order to initialize display

<script type='text/javascript' src='https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js'></script>
<script src="https://raw.github.com/aterrien/jQuery-Knob/master/js/jquery.knob.js"></script>
<input type="text" id="inp1-min" class="knob1" value="0" data-width="120" data-thickness="0.4" />

<script type='text/javascript'>//<![CDATA[ 
$(window).load(function(){
  jQuery(document).ready(function ($) {

      //initialize all
      $('.knob1').knob({
          'min': 0,
              'max': 100,
              'step': 1,
              'readOnly': false,
              'linecap': 'round',
              'displayInput': true,
              'angleOffset': -125,
              'angleArc': 250
      });

      $('#inp1-min').trigger('configure', {
          'format': function (v) {
              return v + ' %';
          }
      });
    $('#inp1-min').trigger('change');
  });
});//]]>  

</script>

la-ci avatar Apr 23 '14 10:04 la-ci

$('.dial').knob({

'format' : function (value) { return value + '%';

}});

Rubel-hossain avatar Mar 21 '16 02:03 Rubel-hossain

i want to add some condition like if (true) add % else donot add. how can i write it

railsfactory-robin avatar Apr 19 '17 06:04 railsfactory-robin

can you specify a bit more the condition? you are inside function that has variable named value passed to it. if you want for example test for positive value you simply put

$('.dial').knob({
'format' : function (value) {
  if (value > 0) {
     return value + '%';
  } else {
    return value;
  }
}});

la-ci avatar Apr 19 '17 09:04 la-ci

hi , Thanks for your reply .

i have element as a object, i want like if element.category == 'reading' then i need % else i dont want.

On Wed, Apr 19, 2017 at 3:15 PM, Laci Kosco [email protected] wrote:

can you specify a bit more the condition? you are inside function that has variable named value passed to it. if you want for example test for positive value you simply put

$('.dial').knob({'format' : function (value) { if (value > 0) { return value + '%'; } else { return value; } }});

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/aterrien/jQuery-Knob/issues/193#issuecomment-295191983, or mute the thread https://github.com/notifications/unsubscribe-auth/AM_Zg0oIF-_ygBZgUIcRsSnlGvnCGwhwks5rxdfCgaJpZM4Bv9Qh .

-- Robin Thomas Software engineer | Sedin technology Mob : +91 9535787496

railsfactory-robin avatar Apr 19 '17 11:04 railsfactory-robin

so have you tried to use element.category in the if statement? maybe if you are passing element instead of value, you can use element.anything to work with .... maybe, just maybe, because i see only fragment, you can use

<input type="text" class="dial" value ="element" />

and in function do something like

$('.dial').knob({
'format' : function (element) {
  if (element.category == 'reading') {
     return element.value + '%';
  } else {
    return element.value;
  }
}});

let us know if it worked for you

la-ci avatar Apr 20 '17 08:04 la-ci

Hi,

Thank you so much, this code is working for me.

cheers Robin Thomas https://www.facebook.com/77robson7

On Thu, Apr 20, 2017 at 2:00 PM, Laci Kosco [email protected] wrote:

so have you tried to use element.category in the if statement? maybe if you are passing element instead of value, you can use element.anything to work with .... maybe, just maybe, because i see only fragment, you can use

and in function do something like

$('.dial').knob({'format' : function (element) { if (element.category == 'reading') { return element.value + '%'; } else { return element.value; } }});

let us know if it worked for you

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/aterrien/jQuery-Knob/issues/193#issuecomment-295632651, or mute the thread https://github.com/notifications/unsubscribe-auth/AM_Zg3UinYJNmJXUWhtxO_TR47ae_0Bwks5rxxeZgaJpZM4Bv9Qh .

-- Robin Thomas Software engineer | Sedin technology Mob : +91 9535787496

railsfactory-robin avatar Apr 20 '17 09:04 railsfactory-robin

Hi,

Sorry to say that, the code is not working. <input class="graph__knob ', element.category,'" value="', element.value || 0,'" data-max="100" data-fgColor="', color ,'"> this will take only numbers as value if am putting element alone as value (value = element) and trying to fetch in function (v) {console.log(v) ; return v + '%'; } its showing NaN

On Thu, Apr 20, 2017 at 2:45 PM, Robin Thomas [email protected] wrote:

Hi,

Thank you so much, this code is working for me.

cheers Robin Thomas https://www.facebook.com/77robson7

On Thu, Apr 20, 2017 at 2:00 PM, Laci Kosco [email protected] wrote:

so have you tried to use element.category in the if statement? maybe if you are passing element instead of value, you can use element.anything to work with .... maybe, just maybe, because i see only fragment, you can use

and in function do something like

$('.dial').knob({'format' : function (element) { if (element.category == 'reading') { return element.value + '%'; } else { return element.value; } }});

let us know if it worked for you

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/aterrien/jQuery-Knob/issues/193#issuecomment-295632651, or mute the thread https://github.com/notifications/unsubscribe-auth/AM_Zg3UinYJNmJXUWhtxO_TR47ae_0Bwks5rxxeZgaJpZM4Bv9Qh .

-- Robin Thomas Software engineer | Sedin technology Mob : +91 9535787496

-- Robin Thomas Software engineer | Sedin technology Mob : +91 9535787496

railsfactory-robin avatar Apr 20 '17 11:04 railsfactory-robin

you code seems to be not a valid html, maybe it was just cut from some javascript code. if you use value=element, and element is object, you can hardly expect javascript to process it as simple type (being it number or string). have you tried accessing v.value instead of v ?

la-ci avatar Apr 20 '17 12:04 la-ci

Yeh , am binding html from js, i tried , but v.value is NaN , i dynamically assigned classes and its working now reading_knob then it will return with % if it is listening_knob without %

On 20-Apr-2017 6:28 PM, "Laci Kosco" [email protected] wrote:

you code seems to be not a valid html, maybe it was just cut from some javascript code. if you use value=element, and element is object, you can hardly expect javascript to process it as simple type (being it number or string). have you tried accessing v.value instead of v ?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/aterrien/jQuery-Knob/issues/193#issuecomment-295728611, or mute the thread https://github.com/notifications/unsubscribe-auth/AM_Zg9uc4vT4GxmXwjR_mxmasFdPbhzTks5rx1aOgaJpZM4Bv9Qh .

railsfactory-robin avatar Apr 20 '17 13:04 railsfactory-robin

@Rubel-hossain - your method worked perfectly and is the simplest. Thx.

KillerSquid avatar May 26 '17 15:05 KillerSquid