【问题标题】:Trying to render data d3 crossfilter dc.js BarChart. The chart is drawn, but it's empty试图呈现数据 d3 crossfilter dc.js BarChart。图表已绘制,但为空
【发布时间】:2013-03-15 11:10:08
【问题描述】:

我一定是在做一些幼稚的事情,但我无法让我的数据在图表中呈现。

这是我的示例数据:

var data = [
    {    
       date: '02-12-2013',
       val: 13,
    }
    {    
       date: '02-13-2013',
       val: 6,
    }
    ...
]

这是我的代码:

var cf = crossfilter(data);
var dim = cf.dimension(function(d){ return d.val });
var group = dim.group();
var barchart = dc.barChart('#container');

barchart.width(850)
.height(250)
.margins({top: 10, right: 50, bottom: 30, left: 40})
.dimension(dim)
.group(group)
.gap(1)
.x(d3.time.scale()
          .domain([new Date(data[0].date), 
                  new Date(data[data.length-1].date)]))
.xUnits(d3.time.day)
.centerBar(true)
.renderHorizontalGridLines(true)
.renderVerticalGridLines(true)
.render();

我在这里缺少什么?这是图表的屏幕截图:

【问题讨论】:

    标签: javascript d3.js data-visualization crossfilter dc.js


    【解决方案1】:

    尝试使用date 作为您的维度:

    var dim = cf.dimension(function(d){ return d.date });
    

    对于条形图,您的维度通常需要与您的X 轴刻度相匹配。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-22
      • 2021-12-16
      • 1970-01-01
      • 2023-04-08
      相关资源
      最近更新 更多