Accepted answer

Just get the date today. No need to get its date, month, and year because it will return a string. All you have to do is put the date in your x variable to jive with its domain

var today = new Date();
var dd = today.getDate();    //<<===== no need
var mm = today.getMonth()+1; //January is 0!   //<<===== no need
var yyyy = today.getFullYear();  //<<===== no need

.attr("x1", x(today))  //<<== change your code here
.attr("y1", 0)
.attr("x2", x(today))  //<<== and here
.attr("y2", height - - margin.bottom)
.style("stroke-width", 2)
.style("stroke", "red")
.style("fill", "none");

Related Query