0

私は D3.js で実験しようとしていますが、コードは HTML 親ドキュメントのタグに含まれている場合にのみ機能し、外部 JS ドキュメント (つまり script.js) に JavaScript が含まれている場合は機能しません。

index.html で:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <title>D3js Test</title>
  <link href="styles/style.css" rel="stylesheet" />
  <script src="scripts/d3.v3.min.js"></script>
  <script src="scripts/script.js" type="text/javascript"></script>
</head>
<body>

</body>
</html>

そして、私は非常に単純なことをしようとしています

script.js 内

var spaceCircles = [30, 70, 110];

var svgContainer = d3.select("body").append("svg")
                                .attr("width", 200)
                                .attr("height", 200);

var circles = svgContainer.selectAll("circle")
                      .data(spaceCircles)
                      .enter()
                      .append("circle");

var circleAttributes = circles
                   .attr("cx", function (d) { return d; })
                   .attr("cy", function (d) { return d; })
                   .attr("r", 20);

私が欠けているものについて誰にも考えがありますか?

ありがとう、TG

編集@ Carlos487 のおかげで、なんとか動作させることができましたが、jQuery を参照し、doc ready コマンドにすべてを含める必要がありました。これは要らない気がする…

4

3 に答える 3