Home Forums Chart Support set dynamic array to dataPoints

set dynamic array to dataPoints

Viewing 2 posts - 1 through 2 (of 2 total)
  • #19302

    hello, I try set array to dataPoints but that not work, and I don’t know why, maybe somebody can help, thank you
    that the code

        var models = [];
     var cars = [];
      var sumMod;
           var text;
           var count = 0;
         var  dps = [];
         
     window.onload = function() {
          
    /**RECEIVE json**********/
            $(document).ready(function(){
                    /* call the php that has the php array which is json_encoded */
                   $.getJSON('androidSortBySumCars.php', function(data) {
                            /* data will hold the php array as a javascript object */
                           $.each(data, function(key, val) {
                                  /* $('ul').append('<li id="' + key + '">' + val.model + ' ' + val.counter +  '</li>');*/
                                    if(typeof val.model !== "undefined"){// === equal !== not equal
                                      models[count] = val.model;
                                        cars[count++] = val.counter;
                                    }
                            
                            });
                            for(var i=0;i<cars.length; i++){
                                cars[i] =100 * (cars[i]/cars.length);
                            }
                            
                            for(var j=0;j<cars.length; j++){
                                dps.push({
                                     y: cars[j], label: models[j]
                                      
                                            });
                                                }
                        window.alert(dps[0]['y']); //66.66
                       //window.alert(models);    
                      //window.alert(sum);
                    });
    
            });
    /*End RECEIVE json*/
    var chart = new CanvasJS.Chart("chartContainer", {
    	animationEnabled: true,
    	title: {
    		text: "Sum of Cars"
    	},
    	data: [{
    		type: "pie",
    		startAngle: 240,
    		yValueFormatString: "##0.00\"%\"",
    		indexLabel: "{label} {y}",
    		dataPoints: dps
    	}]
    });
    
    chart.render();
    
    }
    #19308

    @shmonikk,

    Can you please check if y value of the dataPoints received from php service is of type number? In case the issue still persists after converting the y value to number please create a JSFiddle reproducing the issue and share it with us along with sample data so that we can look into the code, understand the scenario better and help you out.

    ___________
    Indranil Deo,
    Team CanvasJS

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.