[英]How can I control the date format for d3 scaleTime and remove unwanted clock time ticks?
[英]Can I Parse time in d3 in this format “%H%M”?
HIII,
我有一段時間用這種格式hhmm
,像這樣:2010
我已經試過了:
var timeFormat = d3.time.format("%H%M");
d.Dep_Time1= timeFormat.parse(d.Dep_Time1);
但這不起作用...:s
請問我如何實現以上目標?
一種解決方案是將您的4位數字轉換為字符串,以使D3知道如何解析它:
var times = [2210, 2315, 0817, 1456]; var timeFormat = d3.time.format("%H%M"); times.forEach(function(time){ time = timeFormat.parse(time.toString()); console.log(time); });
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.4.11/d3.min.js"></script>
PS:根據@altocumulus注釋進行編輯(請參見下文)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.