jQuery-Knob
jQuery-Knob copied to clipboard
Adding percentage next to the number?
Is it possible to also reflect in percentage like 10%, 20%?
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 + "%";}
}
);
});
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>
$('.dial').knob({
'format' : function (value) { return value + '%';
}});
i want to add some condition like if (true) add % else donot add. how can i write it
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;
}
}});
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
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
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
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
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 ?
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 .
@Rubel-hossain - your method worked perfectly and is the simplest. Thx.