javascript - how to draw canvas chart using ajax response data? -


<code>enter image description here</code>

this output of code see response has 2 keys day , amount. day , amount have values of array. when trying push these values in empty array, not running. chart empty.

$(document).ready(function(){ $.ajax    ({ type:'post', url:'data.php', success:function(response) {     var result= json.parse(response);     console.log(result); //var count = object.keys(result).length;     //console.log(count);     var dps =[];      for(var i=0; i<result.length;i++)     {       dps.push({"label":result.day[i], "y":result.amount[i]});     }     console.log(dps);    //insert chart-making function here    var chart = new canvasjs.chart("chartcontainer", {    zoomenabled:true,    panenabled:true,    animationenabled:true,    title:{     text: "mychart mysql database"   },   axisx:{     title: "timestamp"  },      axisy:{     title: "mydatapoints",     minimum: 0  },  data: [{     type: "spline",     datapoints:         dps           }] }); chart.render();  }    });    }); 

[[02-jan-16,413],[03-jan-16,14],[04-jan-16,2],[05-jan-16,37], [06-jan-16,50],[07-jan-16,22],[08-jan-16,82]] want covert response data format.

this code of given output. can suggest how this.


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -