'limit the number of ticks on time series x axis (d3)

Trying to create a bar chart with Time type on x axis. I want to only display few ticks on x axis. Below is a small portion of the code. After reading many posts online, I realized I need to use tickValues and also to Time format them. However, still getting a messy x axis. what I am doing wrong?

var parseDate = d3.timeParse("%Y");
g.append("g")
         .attr("transform", "translate(0," + height + ")")
         .call(d3.axisBottom(xScale)
         .tickValues(parseDate(["1890","2000"])))
         .append("text")
         .attr("y", height - 250)
         .attr("x", width - 100)
         .attr("text-anchor", "end")
         .attr("stroke", "black")
         .text("Year");

enter image description here



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source