当前位置: 动力学知识库 > 问答 > 编程问答 >

javascript - How to use D3 scale to convert a continuous domain to a range of ordinal dates?

问题描述:

I've got a continuous set of values from 0 to 1, and would like to map this in the most convenient way to my data, which has 365 dates (each one is formatted as "%Y-%m-%d"). It seemed simple enough before I got started, or maybe it's way too late to be using my head, but I'm getting nowhere.

I've tried

 d3.scale.linear()

.domain([0,1])

.range(d3.extent(data, function(d) {return d.date;}));

and

d3.time.scale()

.domain([0,1])

.range(d3.extent(data, function(d) {return d.date;}));

both of which give output like 1423737864000 (although, at least, this number varies depending on the scale's input).

I've also tried

d3.scale.ordinal()

.domain([0,1])

.range(d3.extent(data, function(d) {return d.date;}));

but this only gives me my first date, Thu Jan 01 2015 00:00:00 GMT-0500 (EST) as output, irrespective of inputs.

Basically, instead of using d3.time.scale.domain() with dates and d3.time.scale.domain() with values, can I using values in the domain and the dates that I've got in my data as the range?

EDIT does it help that I've got the dates arranged in order, beginning with Jan 1 and ending with Dec 31?

分享给朋友:
您可能感兴趣的文章:
随机阅读: