Trying to render data d3 crossfilter dc.js BarChart. The chart is drawn, but it's empty

只愿长相守 提交于 2019-12-22 01:30:00

问题


I must be doing something naive, but I can't get my data to render within the chart.

here's my example data:

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

here's my code:

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();

What am I missing here? Here's the screenshot of the chart:


回答1:


Try to use date as your dimension:

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

For bar chart your dimension usually is what needs to be matched with your X axis scale.



来源:https://stackoverflow.com/questions/15623804/trying-to-render-data-d3-crossfilter-dc-js-barchart-the-chart-is-drawn-but-it

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!