码迷,mamicode.com
首页 > 其他好文 > 详细

[D3] Convert Dates to Numeric Values with Time Scales in D3 v4

时间:2016-12-03 01:23:08      阅读:225      评论:0      收藏:0      [点我收藏+]

标签:date   plot   nothing   ati   about   objects   ons   console   color   

Mapping abstract values to visual representations is what data visualization is all about, and that’s exactly what D3 scales do. This is usually done using pretty straightforward algorithms, but nothing is straightforward when you’re working with Date objects in JavaScript. If you’re plotting temporal data, you need to use a time scale.

 

function scaleTime(){
    var timeScale = d3.scaleTime()
        .domain([new Date(2016,0,1), new Date()])
        .range([0,100]);

    console.log(timeScale(new Date(2016,0,15)));
    console.log(timeScale(new Date(2016,3,15)));
    console.log(timeScale(new Date()));

    console.log(timeScale.invert(50));
}

 

[D3] Convert Dates to Numeric Values with Time Scales in D3 v4

标签:date   plot   nothing   ati   about   objects   ons   console   color   

原文地址:http://www.cnblogs.com/Answer1215/p/6127450.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!