2017-06-20 42 views
1

我有下圖:定製時間表蜱與D3和dc.js

scrollChart 
    ... 
    .x(d3.time.scale().domain([startDate, endDate])) 
    .round(d3.time.minutes) 
    .alwaysUseRounding(true) 
    .xUnits(d3.time.minutes); 

我怎樣才能改變我的.xUnits.round使用每5/10/15分鐘爲時間間隔?

更新:

戈登的回答幫助,但我變焦後有新的問題。

這是5分鐘間隔: enter image description here

我的縮放後,我有不好的圖表:(我怎麼能過濾後「重組」一切以1周分鐘的間隔是真的

enter image description here

+0

[chart.round()](http://dc-js.github.io/dc.js/docs/html/dc.coordinateGridMixin.html#round__anchor)僅影響刷舍入。您可能希望按照您感興趣的時間間隔進行聚合。[以下是在不同時間間隔之間切換的示例。](http://dc-js.github.io/dc.js/examples/switching-time -intervals.html) – Gordon

+0

@戈登你是對的,但我需要定製時間線與我的時間間隔,而不是'月',''''''小時' –

+1

難題,也許嘗試這個線程? https://groups.google.com/forum/m/#!topic/dc-js-user-group/q_dO0pRf3vA – Gordon

回答

1

感謝Gordon的幫助。 我用d3.js version 3this話題。 首先,你需要複製d3_time_interval功能,因爲它沒有暴露出來。

接下來我創建了函數並在分組中使用它。

const n_minutes_interval = (nMins) => { 
    let denom = 6e4*nMins; 
    return d3_time_interval(
     date => new d3_date(Math.floor(date/denom) * denom, 
     (date, offset) => date.setTime(date.getTime() + Math.floor(offset) * denom, 
     date => date.getMinutes()); 
} 

let myTimeInterval = n_minutes_interval(5); 
let myGroup = dim.group(d => myTimeInterval(d)).someReduceFunction();