PHP:d3.js脚本不显示任何内容

PHP:d3.js脚本不显示任何内容,php,jquery,html,d3.js,Php,Jquery,Html,D3.js,问题:我有以下代码,作为一个独立的.html文件运行良好。现在,我希望在一个.php文件中显示它。在.php文件中,我复制粘贴了相同的代码 在显示该.php文件的主页中有一些页眉/页脚和其他html。但是,当我运行它时,除了测线之外,图表不会显示 应该做哪些额外的更改 <!DOCTYPE html> <html> <head> <meta http-equiv="Content-type" content="text/html; c

问题:我有以下代码,作为一个独立的.html文件运行良好。现在,我希望在一个.php文件中显示它。在.php文件中,我复制粘贴了相同的代码

在显示该.php文件的主页中有一些页眉/页脚和其他html。但是,当我运行它时,除了测线之外,图表不会显示

应该做哪些额外的更改

<!DOCTYPE html>

<html>
  <head>    
    <meta http-equiv="Content-type" content="text/html; charset=utf-8">

<div>
      <h4>Testing</h4>
</div>

    <!-- <script type="text/javascript" src="http://mbostock.github.com/d3/d3.js?2.4.5"></script> -->
    <script src="d3.v3.js"></script>

    <!-- Source for example located at: http://bl.ocks.org/1203641 -->

    <style type="text/css">
        .slice text {
            font-size: 16pt;
            font-family: Arial;
        }   
    </style>

    <script>

    var canvasWidth = 500, //width
      canvasHeight = 700,   //height
      outerRadius = 200,   //radius
      color = d3.scale.category20(); //builtin range of colors

    var dataSet = [
      {"legendLabel":"Your child's Percentile", "magnitude":90}, 
      {"legendLabel":"Ahead of your child", "magnitude":10},
//      {"legendLabel":"Three", "magnitude":50}, 
//      {"legendLabel":"Four", "magnitude":16}, 
//      {"legendLabel":"Five", "magnitude":50}, 
//      {"legendLabel":"Six", "magnitude":8}, 
//      {"legendLabel":"Seven", "magnitude":30}
];

    var vis = d3.select("body")
      .append("svg:svg") //create the SVG element inside the <body>
        .data([dataSet]) //associate our data with the document
        .attr("width", canvasWidth) //set the width of the canvas
        .attr("height", canvasHeight) //set the height of the canvas
        .append("svg:g") //make a group to hold our pie chart
          .attr("transform", "translate(" + 1.5*outerRadius + "," + 1.5*outerRadius + ")") // relocate center of pie to 'outerRadius,outerRadius'

    // This will create <path> elements for us using arc data...
    var arc = d3.svg.arc()
      .outerRadius(outerRadius);

    var pie = d3.layout.pie() //this will create arc data for us given a list of values
      .value(function(d) { return d.magnitude; }) // Binding each value to the pie
      .sort( function(d) { return null; } );

    // Select all <g> elements with class slice (there aren't any yet)
    var arcs = vis.selectAll("g.slice")
      // Associate the generated pie data (an array of arcs, each having startAngle,
      // endAngle and value properties) 
      .data(pie)
      // This will create <g> elements for every "extra" data element that should be associated
      // with a selection. The result is creating a <g> for every object in the data array
      .enter()
      // Create a group to hold each slice (we will have a <path> and a <text>
      // element associated with each slice)
      .append("svg:g")
      .attr("class", "slice");    //allow us to style things in the slices (like text)

    arcs.append("svg:path")
      //set the color for each slice to be chosen from the color function defined above
      .attr("fill", function(d, i) { return color(i); } )
      //this creates the actual SVG path using the associated data (pie) with the arc drawing function
      .attr("d", arc);

    // Add a legendLabel to each arc slice...
    arcs.append("svg:text")
      .attr("transform", function(d) { //set the label's origin to the center of the arc
        //we have to make sure to set these before calling arc.centroid
        d.outerRadius = outerRadius + 50; // Set Outer Coordinate
        d.innerRadius = outerRadius + 45; // Set Inner Coordinate
        return "translate(" + arc.centroid(d) + ")";
      })
      .attr("text-anchor", "middle") //center the text on it's origin
      .style("fill", "Purple")
      .style("font", "bold 12px Arial")
      .text(function(d, i) { return dataSet[i].legendLabel; }); //get the label from our original data array

    // Add a magnitude value to the larger arcs, translated to the arc centroid and rotated.
    arcs.filter(function(d) { return d.endAngle - d.startAngle > .2; }).append("svg:text")
      .attr("dy", ".35em")
      .attr("text-anchor", "middle")
      //.attr("transform", function(d) { return "translate(" + arc.centroid(d) + ")rotate(" + angle(d) + ")"; })
      .attr("transform", function(d) { //set the label's origin to the center of the arc
        //we have to make sure to set these before calling arc.centroid
        d.outerRadius = outerRadius; // Set Outer Coordinate
        d.innerRadius = outerRadius/2; // Set Inner Coordinate
        return "translate(" + arc.centroid(d) + ")rotate(" + angle(d) + ")";
      })
      .style("fill", "White")
      .style("font", "bold 12px Arial")
      .text(function(d) { return d.data.magnitude; });

    // Computes the angle of an arc, converting from radians to degrees.
    function angle(d) {
      var a = (d.startAngle + d.endAngle) * 90 / Math.PI - 90;
      return a > 90 ? a - 180 : a;
    }


                  </script>
            </meta>
      </head>
</html>

对我来说很好。唯一的区别是我用远程标记替换了您的脚本标记

<script src="http://d3js.org/d3.v3.min.js"></script>
<script src="http://dimplejs.org/dist/dimple.v2.1.0.min.js"></script>
如果您从另一个PHP文件中包含此文件,请删除doctype、html、body和head标记-它们在生成的文件中不能重复


更新:顺便说一下,div标记不属于head部分

侧注:为什么标记上有结束标记?它们是空标签,因此不需要oneHi Ghost。我在回到这之前试过标签,所以它一定是悄悄地进来了。我移除了它,但得到了相同的结果。我检查过了,所有标记都是平衡的。顺便说一句,也许你的JSF上有一些错误的路径/缺少的文件。是的,它作为一个独立的.html文件运行良好,但不是一个.php文件。此外,d3.v3.js文件已按原样下载,并与此.php文件放在同一文件夹中。请您向我们展示您的php文件?Victor,虽然html都是乱码,但仍能正常工作,但我们会处理好的。但是为什么它不能与我的脚本标记一起工作呢?很难说没有看到父文件。但是正如我所说的,上面发布的文件对于包含betterfrom不是很好,因为它有html和head标签打开和关闭