diff --git a/D3.md b/D3.md index 32a5c97..f2ebbbc 100644 --- a/D3.md +++ b/D3.md @@ -157,7 +157,7 @@ A scale will map a data value to a visual value. 1. Create the scale ```javascript - var xScale = d3.time.scale(); + var xScale = d3.scaleTime(); ``` 1. Set up the visual range @@ -166,23 +166,29 @@ A scale will map a data value to a visual value. xScale.range([0, width]); ``` -1. Set up the date format +1. Set up the time range ```javascript - var dateParser = d3.time.format("%Y%m%d"); + xScale.domain([new Date('2016-1-1'), new Date('2017-1-1')]); ``` - - you can now parse strings of this format into dates +### Dealing with alternate date formats - ```javascript - dateParser.parse('20010101');//returns a date object - ``` +Date formatting options: https://github.com/d3/d3-time-format#locale_format - - can get a formatted string from a date object +To parse an alternate format into a date object - ```javascript - dateParser(new Date()); - ``` +```javascript +var parseTime = d3.timeParse("%Y%m%d"); +parseTime('20160101') //returns a date object +``` + +To create an alternately formated string from a date object + +```javascript +var formatTime = d3.timeFormat("%Y%m%d"); +formatTime(new Date()); //returns a string in the above format +``` ## Axes diff --git a/d3_examples/v4.html b/d3_examples/v4.html new file mode 100644 index 0000000..7722141 --- /dev/null +++ b/d3_examples/v4.html @@ -0,0 +1,15 @@ + + + +
asdf
+ + + + + + +