dc.js icon indicating copy to clipboard operation
dc.js copied to clipboard

Length undefined

Open pdaems opened this issue 13 years ago • 4 comments

Greetings,

Im trying to update my version of dc.js from 1.3 to 1.5. However in the 1.5 i get an error in d3.js cannot read length of undefined. I have 6 pie charts and 2 bar charts on my page. When i remove the barcharts from my page in 1.5 the pie charts render perfectly. In 1.3 the bar charts render aswell.

function d3_layout_stackOffsetZero(data) {
var j = -1, m = data[0].length, y0 = [];
while (++j < m) y0[j] = 0;
return y0;}

I can't seem to find my error. This the code of one of my bar charts:

                 barChart.width(990)
                .height(40)
                .margins({ top: 0, right: 50, bottom: 20, left: 40 })
                .dimension(volumedatedimension)
                .group(volumeGroup)
                .centerBar(true)
                .gap(1)
                .x(d3.time.scale().domain([new Date(1985, 0, 1), new Date(2012, 11, 31)]))
                .round(d3.time.month.round)
                .xUnits(d3.time.months);

This is the definition of the dimension and group that i use:

                            var volumedatedimension = calls.dimension(function (d) {
                                return d.month;
                            });
                            var volumeGroup = volumedatedimension.group().reduceCount();

pdaems avatar Sep 10 '13 12:09 pdaems

I've replicated this bug here in a jsfiddle - no chart is shown and the error is logged to the console. For me, the error manifests if the crossfilter data is empty (data.length is 0, therefore data[0] is undefined) - is this also the case for you?

I'm happy to help on this fwiw.

lorcan avatar Sep 10 '13 15:09 lorcan

I see thanks for your help, the problem is this is normal behaviour in my application. I use some filters to request data through ajax and return it as json. However the result can be empty aswell.

pdaems avatar Sep 10 '13 16:09 pdaems

Hi @pdaems, just issued a pull request (#285) - it appears to me that the problem exists because a variable in dc.utils.GroupStack is not initialised properly if data points are not added. This causes the bug to manifest every time the data is empty (this is normal behaviour for my application too). Could you take a look and see if this is a valid fix? Thanks :-)

lorcan avatar Sep 10 '13 16:09 lorcan

@lorcan @jrideout Thanks this fixed my issue !

pdaems avatar Sep 10 '13 17:09 pdaems