d3.js - 在xAxis上显示时间

时间:2014-07-31 09:43:12

标签: datetime d3.js axis timeline

我正在做this之类的事情。我采用了这个例子。

但是我希望有一个显示日期的x轴,而不仅仅是示例中的一些数字。这是我的代码的重要部分:但它不起作用。我想念一些改变吗?

var lanes = ["lane1","lane2"],
        laneLength = lanes.length,
        items = [{"lane": 0, "id": "before", "start": "2012-04-23 18:25:43", "end": "2012-05-23 18:25:43"},
                {"lane": 0, "id": "crossing", "start": "2012-04-23 18:25:43", "end": "2012-05-23 18:25:43"},
                {"lane": 0, "id": "after", "start": "2012-04-23 18:25:43", "end": "2012-05-23 18:25:43"},
                {"lane": 1, "id": "before", "start": "2012-04-23 18:25:43", "end": "2012-05-23 18:25:43"},
                {"lane": 1, "id": "crossing", "start": "2012-04-23 18:25:43", "end": "2012-05-23 18:25:43"},
                {"lane": 1, "id": "after", "start": "2012-04-23 18:25:43", "end": "2012-05-23 18:25:43"}]
        timeBegin = "2012-04-23 18:25:43",
        timeEnd = "2012-05-23 18:25:43";



        //scales
        var x = d3.time.scale()
                .domain([timeBegin, timeEnd])
                .range([0, w]);
        var x1 = d3.time.scale()
                .range([0, w]);


           //xAxis
        var xAxis = d3.svg.axis()
                    .scale(x)
                    .orient("top");


        chart.append("g")
      .attr("class", "x axisTime")
      .attr("transform", "translate(" + m[3] + "," + (mainHeight + m[0]) + ")")
      .call(xAxis);

0 个答案:

没有答案