jquery - Javascript Error - Undefined -
i trying create format graph. when try getting undefined
console.log
before data. here's code
$(document).ready(function () { var graphdata = new array(); $.getjson("ds/js.json", function (data) { datalength = returneddata.data.length; var x = new array(); var y = new array(); var mytext, dataa, f; (i = 0; < datalength; i++) { x[i] = data.data[i].avgprice; y[i] = data.data[i].numproducts; } (var = 0; < 6; a++) { mytext = "x:" + x[a] + "," + "y:" + y[a] + "}" + "," + "{"; dataa = dataa + mytext; } console.log(dataa); var f = "[{data : [{" + dataa; console.log(f); }); drawgraph(graphdata); });
console output :
undefinedx:87.6,y:85},{x:116.08,y:61},{x:113.11,y:49},{x:181.37,y:65},{x:138.14,y:74},{x:66.03,y:89},x:66.03,y:89},{
what doing wrong here? , want separate format a=5, stops ", {" coming @ end.
you shouldn't building object through string concatenation that. i'd recommend building array of objects so:
var dataa = []; (var = 0; < 6; a++) { var newobj = {x: + x[a], y: + y[a]}; dataa.push(newobj); }
and generate f
have:
var f = json.stringify([{data: dataa}]);
Comments
Post a Comment