The reason is you are drawing same line again and again on the same x1/x2/y1/y2 for dataset.
This will make your line crooked:
var svg = d3.select('svg');
var dataSet = [10,20,30,20,30,20,30,20,30,20,30,20,30,20,30,20,30];//many data 17 times you will draw line.
var myLine = svg.selectAll('line')
.data(dataSet)
.enter()
.append('line')
.style("stroke", "blue")
.attr('x1', function(d) { return 100; })
.attr('y1', function(d) { return 200; })
.attr('x2', function(d) { return 300; })
.attr('y2', function(d) { return 40; });
Working example here
Now the crookedness will go coz you are making a single line on the x1/x2/y1/y2
var svg = d3.select('svg');
var dataSet = [10];//you will draw line ones
var myLine = svg.selectAll('line')
.data(dataSet)
.enter()
.append('line')
.style("stroke", "blue")
.attr('x1', function(d) { return 100; })
.attr('y1', function(d) { return 200; })
.attr('x2', function(d) { return 300; })
.attr('y2', function(d) { return 40; });
Working example here
So in short you should not be drawing same line over and over again...
Hope this helps!