d3.js的时间间隔

时间:2014-05-16 16:45:54

标签: javascript d3.js

我必须绘制一组矩形,表示当月的一天范围。

svg.selectAll(".month")
  .data(function() { return getMonths(year); })
  .enter().append("path")
  .attr("class", "month")
  .attr("d", monthPath);

我的功能是:

function getMonths(year){
   var months = d3.time.months(new Date(year, 0, 1), new Date(year + 1, 0, 1));
   return months;
}

这个函数被称为一组年份,如[2003,2004,2005等等..] 如果我将我的功能称为一年,它不起作用,相反如果我这样用这种方式调用这个功能:

function getMonths(year){
   var months = d3.time.months(new Date(2012, 0, 1), new Date(2012 + 1, 0, 1));
   return months;
}

它有效。

为什么我有这个问题? 感谢。

0 个答案:

没有答案
相关问题