我有一些我想用它来创建对角线的点。我不想使用树形布局,我只想要两个点和一条对角线。
以下代码引发错误:“Uncaught TypeError: Cannot read property 'y' of undefined”
---更新的工作代码------
<html>
<head>
<script src="http://d3js.org/d3.v3.min.js"></script>
</head>
<body>
<script type="text/javascript">
//The data for our line
var lineData = [
{
"source": {
"x": 100,
"y": 300
},
"target": {
"x": 200,
"y": 400
},
"number":5
},
{
"source": {
"x": 150,
"y": 350
},
"target": {
"x": 250,
"y": 450
},
"number":10
},
];
var lineFunction = d3.svg.diagonal()
.projection(function(d) { return [d.y, d.x] })
var svgContainer = d3.select("body").append("svg")
.attr("width", 1000)
.attr("height", 1000);
svgContainer.selectAll("lines")
.data(lineData)
.enter()
.append("path")
.attr("d", lineFunction)
.attr("stroke", "blue")
.attr("stroke-width", function(d) { return d.number+"px"})
.attr("fill", "none");
</script>
</body>
</html>