Using the time scale
Often, we perform analysis on a data set that is time- and date-sensitive, therefore, D3 provides a built-in time scale to help perform this type of mapping. In this recipe, we will learn how to use D3 time scale.
Getting Ready
Open your local copy of the following file in your web browser:
https://github.com/NickQiZhu/d3-cookbook/blob/master/src/chapter4/time-scale.html
How to do it...
First, let's take a look at the following code example:
<div id="time" class="clear"> <span>Linear Time Progression<br></span> <span>Mapping [01/01/2013, 12/31/2013] to [0, 900]<br></span> </div> <script type="text/javascript"> var start = new Date(2013, 0, 1), // <-A end = new Date(2013, 11, 31), range = [0, 1200], time = d3.time.scale().domain([start, end]) // <-B .rangeRound(range), // <-C max = 12, data = []; for (var...