2

Im trying to get a donut chart with multiple series where the user can reset its shares by sliding. All other series should recalculate depending on its previous value.

I've tried to fiddle around and working with values does not seems to be the problem but in this case it should actually keep te value to a 100 and change the data-angleOffset and data-angleArc so that the donut is always filled up completely.

http://jsfiddle.net/yccu/7zfs5881/5/

This is what I came up with so far also by using others code:

$(function () {
   $(".knob").knob({
change: function (value) {
var chart_id = this.$.attr('id');
var new_val = value;
var arr =new Array();
$('.knob').each(function(){
    arr.push({
    id:$(this).attr('id'),
    val:$(this).val(),
  });   
})
var ttl_val = 0;
var ttl_pct = 0 ;
$.each(arr, function( key, value ) {
ttl_pct = parseFloat(ttl_pct) + parseFloat(value.val);
})
ttl_pct = ttl_pct - new_val;
$.each(arr, function( key, value ) {
    if (value.id != chart_id){
        var other_val = ((parseFloat(value.val)/parseFloat(ttl_pct))*(100-parseFloat(new_val))).toFixed(2);
    $('#'+value.id).val(other_val).trigger('change');
    $('#input_'+value.id).val(other_val);
 }else
 {
    $('#input_'+chart_id).val(new_val);
 }
});
   $('#change_id').val(chart_id);
   $('#change_val').val(value);


}
});
YCuvelie
  • 87
  • 1
  • 5

0 Answers0