Javascript d3实现可以在firefox/chrome上运行,但不能在iPad上运行

Javascript d3实现可以在firefox/chrome上运行,但不能在iPad上运行,javascript,d3.js,cross-browser,circle-pack,Javascript,D3.js,Cross Browser,Circle Pack,因此,我有一些源代码,使用d3.json通过HTTP get请求获取一些json,并将其可视化……它在chrome和firefox上运行得非常好,但当我尝试在safari或chrome的移动verison上运行它时,它崩溃了。在iOS safari上运行时,js遇到空的“d”对象时会发现空类型错误 <em><!DOCTYPE html> <html> <head> <script type="text/javascript" src="d3.

因此,我有一些源代码,使用d3.json通过HTTP get请求获取一些json,并将其可视化……它在chrome和firefox上运行得非常好,但当我尝试在safari或chrome的移动verison上运行它时,它崩溃了。在iOS safari上运行时,js遇到空的“d”对象时会发现空类型错误

<em><!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="d3.v2.js"> 
</script>

<link rel="stylesheet" href="style.css" type="text/css">
<link rel="stylesheet" href="syntax.css" type="text/css">
<link rel="stylesheet" href="pack.css" type="text/css">

</head>


<body>


    <div id="chart"></div>
    <svg width="960" height="960" class="pack">
    <script type="text/javascript">


    setInterval(function(){
        var width = 960,
            height = 960,
            format = d3.format(",d");

        var pack = d3.layout.pack()
            .size([width - 4, height -4])
            .value(function(d) { return d.size; });

        var vis = d3.select("#chart").append("svg")
            .attr("width", width)
            .attr("height", height)
            .attr("class", "pack")
            .append("g")
            .attr("transform", "translate(2, 2)");

        d3.json("http://localhost:8080/cluster", function(json) {       

                //do visualization
                var node = vis.data([json]).selectAll("g.node")
                 .data(pack.nodes)
                 .enter().append("g")
                 .attr("class", function(d) {return d.children ? "node" : "leaf node" ;})
                 .attr("transform", function(d) {return "translate(" + d.x + "," + d.y +")"; });

                node.append("title")
                    .text(function(d) { return d.name + (d.children ? "" : ": " + format(d.size)); });

                node.append("circle")
                .attr("r", function(d) { return d.r; });

                node.filter(function(d) { return !d.children; }).append("text")
                .attr("text-anchor", "middle")
                .attr("dy", ".3em")
                .text(function(d) { return d.name.substring(0, d.r / 3); });

        }
);
                //log
    }, 1000);





        </script>
</body>
</html>

</em>

您似乎在
标记前面有一行散乱的HTML,它阻止了脚本的执行

<svg width="960" height="960" class="pack">

去掉这个,它应该可以工作(在iOS 5.1上测试)


请注意,此
标记缺少其
xmlns
命名空间(
http://www.w3.org/2000/svg
),所以无论如何都会引起问题。

我想知道localhost在移动版本中是否有不同的含义?我会尝试使用您的IP地址。我使用的是我的IP地址,我的移动浏览器接收JSON,但当尝试生成svg元素时,它会遇到空svg属性…因此我做了更改,并在iOS safari上运行时将其归结为最后一个错误。。。第6081行的Javascript错误类型错误:表达式“d”[null]的结果不是对象。同样的代码在我的macbook上的safari/firefox/chrome上运行时没有出现错误,但在我的iPad上运行时出现了类型错误。我仍然在运行过时的iOS版本。这可能是问题所在吗?我验证了这个问题与我的json的格式无关,因为即使我传入flare.json(由d3.json的github提供),我也会遇到同样的错误。你能发布你正在使用的代码吗?我测试了上面的代码,没有出现令人不快的行,它对我来说很好。请注意,由于跨源安全策略,JSON必须从与页面本身相同的域和端口提供服务。我发布了我的服务器配置…JSON和源文件是从同一服务器上的相同端口发送的,所以这不应该是问题。解决了这个问题。原来我忘了更新d3.json的url参数…我引用的是localhost,而不是运行hte服务器的机器的ip地址。。。
<svg width="960" height="960" class="pack">