我将Json数据存储到变量中并将此数据调用到jquery中的Morris.Bar函数中,这样做我正在设置未定义的数据并且无法显示图形 下面是我的代码。看看,请帮助我真正重要。
var datajson='{"x":"sales", "y":"46146","z":"46146","a":"46146"},{"x":"swami", "y":"460104","z":"460104","a":"460104"},';
var content = JSON.stringify(datajson);
var parsedContent = JSON.parse(content);
if (typeof Morris != 'undefined') {
Morris.Bar({
data : [parsedContent],
element : 'chart31',
axes : true,
xkey : 'x',
ykeys : [ 'y', 'z', 'a' ],
labels : [ 'Quotation amount ', 'Purchase order amount ', 'Invoice amount' ],
barColors : [ 'red', 'blue', 'green' ]
});
}
答案 0 :(得分:1)
您的JSON数据无法解析。你有一个js错误 - 检查你的控制台:
var datajson='{"x":"sales", "y":"46146","z":"46146","a":"46146"},{"x":"swami", "y":"460104","z":"460104","a":"460104"},';
应该是:
var datajson='[{"x":"sales", "y":"46146","z":"46146","a":"46146"},{"x":"swami", "y":"460104","z":"460104","a":"460104"}]';
然后改变:
data: parsedContent,