嗨,我正在学习如何使用 protovis,到目前为止一切都很好,但现在我偶然发现了一个我似乎无法解决的问题。
以下是代码。(我的标题中加载了最新的 jquery)
<script type="text/javascript+protovis">
var dataURL = "http://eagereyes.org/media/2010/protovis-primer/earthquakes.json";
var JSONdata = $.ajax({ type: "GET", url: dataURL, async: false }).responseText;
var earthquakes = JSON.parse(JSONdata);
var width = 560;
var height = 245;
var barWidth = width/earthquakes.length;
var gap = 2;
new pv.Panel().width(width).height(height+5)
.add(pv.Bar)
.data(earthquakes)
.bottom(0)
.width(barWidth-gap)
.height(function(d) d.Magnitude * (height/9))
.left(function() this.index * barWidth)
.root.render();
当我在 Firefox 中尝试此操作时,我收到此警报:
Syntax:Error JSON.parse
我已经在http://www.jsonlint.com/上验证了 JSON 。所以问题一定出在其他地方。
有谁知道这里发生了什么?
编辑
我尝试在 protoviewer 应用程序中加载相同的数据:http ://www.rioleo.org/protoviewer/ 它可以工作。所以它必须是代码。