Reputation: 869
I have an SVG inside a div in the html body and I am using d3 to append a "rect" to this SVG, but the rect is not getting generated.
<script>
//Select the SVG Container
var svgContainer = d3.select("#svg_container");
//Draw the Rectangle
var rectangle = svgContainer.append("rect").attr("x", 10).attr("y", 10).attr("width", 50).attr("height", 100);
<svg id="svg_container" width="1000px" height="800px"</svg>
Here is a plunkr added - https://embed.plnkr.co/aNW8NtiRfS6FkSQMHtkB/
Any help in generating the "rect" would be appreciated.
Upvotes: 0
Views: 301
Reputation: 662
You need to load the script.js after loading your libraries.
http://plnkr.co/edit/8qxmu5KpPZroGhB1odGK?p=preview
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="style.css">
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<script type="text/javascript" src="http://mbostock.github.com/d3/d3.js"></script>
<script src="http://d3js.org/d3.v3.min.js" charset="utf-8"></script>
<script src="script.js"></script>
</head>
<body ng-app="MyApp">
<div id="container" ng-controller="driversController">
<div id="ElementPane" class="container">
<svg id="svg_container" width="1000px" height="800px"></svg>
</div>
</div>
</body>
</html>
Upvotes: 1