我正在尝试为图表创建格式。当我尝试这样做时,我会在数据之前得到一个undefined
with console.log
。这是我的代码
$(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;
for (i = 0; i < dataLength; i++) {
x[i] = Data.data[i].avgPrice;
y[i] = Data.data[i].numProducts;
}
for (var a = 0; a < 6; a++) {
mytext = "x:" + x[a] + "," + "y:" + y[a] + "}" + "," + "{";
dataa = dataa + mytext;
}
console.log(dataa);
var f =
"[{data : [{" + dataa;
console.log(f);
});
drawGraph(graphData);
});
控制台输出:
未定义x: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},{
我在这里做错了什么?而且我还想要一个单独的 a=5 格式,以阻止最后出现的“,{”。