How can I make my x-axes start 1 year before the minimum date in the years array?

Hi all

How can I make my x-axes start 1 year before the minimum date in the years array? To avoid having any datapoints right on the y-axes

Thanks for your time

Jaime

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36

Challenge: Visualize Data with a Scatterplot Graph

Link to the challenge:

As you know, you can use D3.min() to get the minimum date. If you create a new date which has the same time as the minimum date (by using new Date(minDate.getTime())), you can use .getYear() and .setYear() to decrement the year by one:

const startXDate = new Date(minDate.getTime());
startXDate.setYear(startXDate.getYear() - 1);

And then you can use startXDate in your xScale.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.