我正在尝试将图像从数组加载到 svg 画布中,但无法使此代码正常工作。
我正在尝试使用 Chrome 对其进行调试,但我无法做到。图像是空白的,我不知道如何继续。
<html>
<head>
<script type="text/javascript" src="http://mbostock.github.com/d3/d3.js"></script>
<style type="text/css">
body {
background-image:url('BG.png')
}
</style>
<title>Drag And Drop</title>
</head>
<body>
<script type="text/javascript">
window.onload = function(){
var NumImages = [
{ 'x' :200, 'y':90, 'width': 450, 'height':200, 'href' : 'numbers.jpeg' },
];
var circleData = [
{ "cx": 20, "cy": 20, "radius": 20, "color" : "green" },
{ "cx": 70, "cy": 70, "radius": 20, "color" : "purple" }];
var rectangleData = [
{ "rx": 110, "ry": 110, "height": 30, "width": 30, "color" : "blue" },
{ "rx": 160, "ry": 160, "height": 30, "width": 30, "color" : "red" }];
var svgContainer = d3.select("body").append("svg")
.attr("width",700)
.attr("height",700)
.attr("margin-top", 100);
var images = svgContainer.selectAll("image")
.data(NumImages)
.enter()
.append("image");
svgContainer.append("image")
.attr('x',200)
.attr('y',90)
.attr('width', 50)
.attr('height', 200)
.attr("xlink:href", "2-image.jpg");
};
</script>
</body>
</html>