d3.tsv in version 4:
When changing the data from Bostock's code from a TSV to a JSON (or, more precisely, to a variable), you forgot something important: In the new D3 v4.x, d3.tsv
function creates an array property called columns
.
This property contains all the headers of the TSV file as an array. In the original code, if you console.log(data.columns)
, you'll get this:
["date", "New York", "San Francisco", "Austin"];
So, basically, for your code to work, all I did was adding this property:
data.columns = ["date", "New York", "San Francisco", "Austin"];
Here is your fiddle: https://jsfiddle.net/uz9rtcwd/
PS: You have a wrong date format. Also, you have to parse the dates in the data
array (this step corresponds to the accessor function in the d3.tsv
, but keep in mind that d3.json
has no accessor function).
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…