首页 > 代码库 > [D3] Convert Dates to Numeric Values with Time Scales in D3 v4
[D3] Convert Dates to Numeric Values with Time Scales in D3 v4
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
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。