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

Posted Answer1215

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[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的主要内容,如果未能解决你的问题,请参考以下文章

108. Convert Sorted Array to Binary Search Tree

Pandas `read_json` 函数将字符串转换为 DateTime 对象,即使指定了 `convert_dates=False` 属性

Given an array where elements are sorted in ascending order, convert it to a height balanced BST.(示例

405. Convert a Number to Hexadecimal

108. Convert Sorted Array to Binary Search Tree

Convert Sorted Array to Balanced Binary Search Tree