我正在构建一个动态xChart。我传递的动态数据是一个预先构建的字符串,可以通过 js 转换为对象:
{"data": [{"x":"car insurance companies","y":1417},
{"x":"insurance companies","y":17201},
{"x":"auto insurance companies","y":892},
{"x":"car insurance quote","y":3280},
{"x":"auto insurance quote","y":988}]}
这是 xCharts 需要的参数代码示例片段:
var data = {
"xScale": "ordinal",
"yScale": "linear",
"main": [
{
"className": ".pizza",
"data": [
{
"x": "Pepperoni",
"y": 4
},
{
"x": "Cheese",
"y": 8
}
]
}
]
};
这是我的一组参数:
var vars = {
"xScale": "ordinal",
"yScale": "linear",
"type": "bar",
"main": [
{
"className": ".topsy-results"
}
]
};
我需要将我data
的对象添加到main
我的参数列表中的对象中以使其完整。如果我$.parseJSON
是data
对象,它会给我一个不起作用的对象。如何解析data
对象以获得我需要的格式(使其与我提供的示例代码匹配)?