Home Ask Login Register

Developers Planet

Your answer is one click away!

Abdul February 2016

Facing issues while grouping data for bar chart in dc js using crossfilter

`d3.json('dc_test_case.json', function(error, data) {
            var data = data;

            var ndx = crossfilter(data);

            homeDim = ndx.dimension(function(d){
                return d.Inning;

            nameDim = ndx.dimension(function(d){
                if(d.Inning === "England batting"){
                return d.Name;

             runName = nameDim.group().reduceSum(function(d) {

                if(d.Inning === "England batting") {
                return Number(d.Runs);


            var England_batting = dc.barChart("#England_batting");
                .yAxisLabel(".", 50)
                .xAxisLabel("U", 50)
                .y(d3.scale.linear().domain([0, 200]))



The bar chart of England batting are not correct, there data is wrong. I think I shouldn't use reduceSum to group data. I don't know what should I use... Anyone solve this issue...

json of this code is given below...

        "Name": "ME Trescothick",
        "Out": "c Hussey b Symonds",
        "Runs": "41",
        "Minutes": "55",
        "Balls": "37",
        "4s": "5",
        "6s": "",
        "SR": "110.81",
        "Home": "England",
        "Away": "Australia",
        "Date": "Jun 13, 2005",
        "Ground": "Southampton",


Ethan Jewett February 2016

Switch to the following, I think:

runName = nameDim.group().reduceSum(function(d) {
  if(d.Inning === "England batting") {
    return Number(d.Runs);
  } else {
    return 0;

The problem is that you return undefined in the event that Australia is batting, and 15 + undefined evaluates to NaN.

Also: Please create a working example in the future. I was able to just eyeball this one, but there is no way for me to check if my solution actually works. You are far far more likely to get help if you create a working example.

Post Status

Asked in February 2016
Viewed 1,243 times
Voted 6
Answered 1 times


Leave an answer

Quote of the day: live life

Devs Planet ®

2014-2016 www.devsplanet.com

Devs Planet © all rights reserved