Home forums Using CanvasJS set dynamic array to dataPoints

Tagged: ,

This topic contains 1 reply, has 2 voices, and was last updated by  Indranil Deo 6 months, 2 weeks ago.

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

    shmonikk
    Member

    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

    Indranil Deo
    Member

    @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 share a jsfiddle along with sample data.

    ___________
    Indranil Deo,
    Team CanvasJS

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

You must be logged in to reply to this topic.