javascript - 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"); england_batting.width(700) .height(480) .gap(30) .yaxislabel(".", 50) .xaxislabel("u", 50) .dimension(namedim) .group(runname) .x(d3.scale.ordinal().domain(namedim)) .xunits(dc.units.ordinal) .y(d3.scale.linear().domain([0, 200])) .elasticy(true) .renderhorizontalgridlines(true) .rendertitle(true) .brushon(true); dc.renderall(); }); the bar chart of england batting not correct, there data wrong. think shouldn't use reducesum group data. don't know should use... solve issue...
json of code 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", "series": "australia tour of england , scotland", "match_no": "only t20i", "winning_info": "england won 100 runs", "inning": "england batting", "id": "569aa1f87e655d7e6af61d3a" }, { "name": "kp pietersen", "out": "c hayden b clarke", "runs": "34", "minutes": "19", "balls": "18", "4s": "3", "6s": "1", "sr": "188.88", "home": "england", "away": "australia", "date": "jun 13, 2005", "ground": "southampton", "series": "australia tour of england , scotland", "match_no": "only t20i", "winning_info": "england won 100 runs", "inning": "england batting", "id": "569aa1f87e655d7e6af61d3b" }, { "name": "a flintoff", "out": "c symonds b kasprowicz", "runs": "6", "minutes": "9", "balls": "5", "4s": "", "6s": "", "sr": "120.00", "home": "england", "away": "australia", "date": "jun 13, 2005", "ground": "southampton", "series": "australia tour of england , scotland", "match_no": "only t20i", "winning_info": "england won 100 runs", "inning": "england batting", "id": "569aa1f87e655d7e6af61d3c" }, { "name": "go jones†", "out": "c kasprowicz b mcgrath", "runs": "19", "minutes": "17", "balls": "14", "4s": "4", "6s": "", "sr": "135.71", "home": "england", "away": "australia", "date": "jun 13, 2005", "ground": "southampton", "series": "australia tour of england , scotland", "match_no": "only t20i", "winning_info": "england won 100 runs", "inning": "england batting", "id": "569aa1f87e655d7e6af61d3d" }, { "name": "mp vaughan*", "out": "c ponting b symonds", "runs": "", "minutes": "2", "balls": "1", "4s": "", "6s": "", "sr": "0.00", "home": "england", "away": "australia", "date": "jun 13, 2005", "ground": "southampton", "series": "australia tour of england , scotland", "match_no": "only t20i", "winning_info": "england won 100 runs", "inning": "england batting", "id": "569aa1f87e655d7e6af61d3e" }, { "name": "pd collingwood", "out": "c ponting b mcgrath", "runs": "46", "minutes": "28", "balls": "26", "4s": "5", "6s": "2", "sr": "176.92", "home": "england", "away": "australia", "date": "jun 13, 2005", "ground": "southampton", "series": "australia tour of england , scotland", "match_no": "only t20i", "winning_info": "england won 100 runs", "inning": "england batting", "id": "569aa1f87e655d7e6af61d3f" }, { "name": "aj strauss", "out": "b gillespie", "runs": "18", "minutes": "15", "balls": "16", "4s": "1", "6s": "", "sr": "112.50", "home": "england", "away": "australia", "date": "jun 13, 2005", "ground": "southampton", "series": "australia tour of england , scotland", "match_no": "only t20i", "winning_info": "england won 100 runs", "inning": "england batting", "id": "569aa1f87e655d7e6af61d40" }, { "name": "vs solanki", "out": "c hussey b mcgrath", "runs": "9", "minutes": "5", "balls": "5", "4s": "1", "6s": "", "sr": "180.00", "home": "england", "away": "australia", "date": "jun 13, 2005", "ground": "southampton", "series": "australia tour of england , scotland", "match_no": "only t20i", "winning_info": "england won 100 runs", "inning": "england batting", "id": "569aa1f87e655d7e6af61d41" }, { "name": "j lewis", "out": "not out", "runs": "", "minutes": "1", "balls": "", "4s": "", "6s": "", "sr": "-", "home": "england", "away": "australia", "date": "jun 13, 2005", "ground": "southampton", "series": "australia tour of england , scotland", "match_no": "only t20i", "winning_info": "england won 100 runs", "inning": "england batting", "id": "569aa1f87e655d7e6af61d42" }, { "name": "extras", "out": "(lb 1, w 3, nb 2)", "runs": "6", "minutes": "", "balls": "", "4s": "", "6s": "", "sr": "", "home": "england", "away": "australia", "date": "jun 13, 2005", "ground": "southampton", "series": "australia tour of england , scotland", "match_no": "only t20i", "winning_info": "england won 100 runs", "inning": "england batting", "id": "569aa1f87e655d7e6af61d43" }, { "home": "england", "away": "australia", "date": "jun 13, 2005", "ground": "southampton", "series": "australia tour of england , scotland", "match_no": "only t20i", "winning_info": "england won 100 runs", "inning": "england batting", "id": "569aa1f87e655d7e6af61d44", "total": "total", "total-d": "(8 wickets; 20 overs; 79 mins)", "r": "179", "rpo": "(8.95 runs per over)" }, { "name": "gd mcgrath", "runs": "31", "4s": "4", "6s": "", "home": "england", "away": "australia", "date": "jun 13, 2005", "ground": "southampton", "series": "australia tour of england , scotland", "match_no": "only t20i", "winning_info": "england won 100 runs", "inning": "australia bowling", "id": "569aa1f87e655d7e6af61d45", "over": "4", "maiden": "", "wickets": "3", "economy": "7.75", "0s": "10" }, { "name": "b lee", "runs": "31", "4s": "4", "6s": "", "home": "england", "away": "australia", "date": "jun 13, 2005", "ground": "southampton", "series": "australia tour of england , scotland", "match_no": "only t20i", "winning_info": "england won 100 runs", "inning": "australia bowling", "id": "569aa1f87e655d7e6af61d46", "over": "3", "maiden": "", "wickets": "", "economy": "10.33", "0s": "6" }, { "name": "ms kasprowicz", "runs": "28", "4s": "3", "6s": "", "home": "england", "away": "australia", "date": "jun 13, 2005", "ground": "southampton", "series": "australia tour of england , scotland", "match_no": "only t20i", "winning_info": "england won 100 runs", "inning": "australia bowling", "id": "569aa1f87e655d7e6af61d47", "over": "3", "maiden": "", "wickets": "1", "economy": "9.33", "0s": "2" }, { "name": "jn gillespie", "runs": "49", "4s": "6", "6s": "2", "home": "england", "away": "australia", "date": "jun 13, 2005", "ground": "southampton", "series": "australia tour of england , scotland", "match_no": "only t20i", "winning_info": "england won 100 runs", "inning": "australia bowling", "id": "569aa1f87e655d7e6af61d48", "over": "4", "maiden": "", "wickets": "1", "economy": "12.25", "0s": "5" }, { "name": "a symonds", "runs": "14", "4s": "1", "6s": "", "home": "england", "away": "australia", "date": "jun 13, 2005", "ground": "southampton", "series": "australia tour of england , scotland", "match_no": "only t20i", "winning_info": "england won 100 runs", "inning": "australia bowling", "id": "569aa1f87e655d7e6af61d49", "over": "3", "maiden": "", "wickets": "2", "economy": "4.66", "0s": "7" }, { "name": "mj clarke", "runs": "25", "4s": "1", "6s": "1", "home": "england", "away": "australia", "date": "jun 13, 2005", "ground": "southampton", "series": "australia tour of england , scotland", "match_no": "only t20i", "winning_info": "england won 100 runs", "inning": "australia bowling", "id": "569aa1f87e655d7e6af61d4a", "over": "3", "maiden": "", "wickets": "1", "economy": "8.33", "0s": "4" }, { "name": "ac gilchrist†", "out": "c pietersen b gough", "runs": "15", "minutes": "11", "balls": "14", "4s": "3", "6s": "", "sr": "107.14", "home": "england", "away": "australia", "date": "jun 13, 2005", "ground": "southampton", "series": "australia tour of england , scotland", "match_no": "only t20i", "winning_info": "england won 100 runs", "inning": "australia batting", "id": "569aa1f87e655d7e6af61d4b" }, { "name": "ml hayden", "out": "c pietersen b gough", "runs": "6", "minutes": "12", "balls": "4", "4s": "1", "6s": "", "sr": "150.00", "home": "england", "away": "australia", "date": "jun 13, 2005", "ground": "southampton", "series": "australia tour of england , scotland", "match_no": "only t20i", "winning_info": "england won 100 runs", "inning": "australia batting", "id": "569aa1f87e655d7e6af61d4c" }, { "name": "a symonds", "out": "c pietersen b lewis", "runs": "", "minutes": "5", "balls": "2", "4s": "", "6s": "", "sr": "0.00", "home": "england", "away": "australia", "date": "jun 13, 2005", "ground": "southampton", "series": "australia tour of england , scotland", "match_no": "only t20i", "winning_info": "england won 100 runs", "inning": "australia batting", "id": "569aa1f87e655d7e6af61d4d" }, { "name": "mek hussey", "out": "c flintoff b gough", "runs": "1", "minutes": "6", "balls": "6", "4s": "", "6s": "", "sr": "16.66", "home": "england", "away": "australia", "date": "jun 13, 2005", "ground": "southampton", "series": "australia tour of england , scotland", "match_no": "only t20i", "winning_info": "england won 100 runs", "inning": "australia batting", "id": "569aa1f87e655d7e6af61d4e" }, { "name": "rt ponting*", "out": "c solanki b lewis", "runs": "", "minutes": "6", "balls": "3", "4s": "", "6s": "", "sr": "0.00", "home": "england", "away": "australia", "date": "jun 13, 2005", "ground": "southampton", "series": "australia tour of england , scotland", "match_no": "only t20i", "winning_info": "england won 100 runs", "inning": "australia batting", "id": "569aa1f87e655d7e6af61d4f" }, { "name": "dr martyn", "out": "c trescothick b lewis", "runs": "4", "minutes": "6", "balls": "4", "4s": "1", "6s": "", "sr": "100.00", "home": "england", "away": "australia", "date": "jun 13, 2005", "ground": "southampton", "series": "australia tour of england , scotland", "match_no": "only t20i", "winning_info": "england won 100 runs", "inning": "australia batting", "id": "569aa1f87e655d7e6af61d50" }, { "name": "b lee", "out": "c harmison b collingwood", "runs": "15", "minutes": "29", "balls": "20", "4s": "1", "6s": "", "sr": "75.00", "home": "england", "away": "australia", "date": "jun 13, 2005", "ground": "southampton", "series": "australia tour of england , scotland", "match_no": "only t20i", "winning_info": "england won 100 runs", "inning": "australia batting", "id": "569aa1f87e655d7e6af61d51" }, { "name": "ms kasprowicz", "out": "not out", "runs": "3", "minutes": "16", "balls": "5", "4s": "", "6s": "", "sr": "60.00", "home": "england", "away": "australia", "date": "jun 13, 2005", "ground": "southampton", "series": "australia tour of england , scotland", "match_no": "only t20i", "winning_info": "england won 100 runs", "inning": "australia batting", "id": "569aa1f87e655d7e6af61d52" }, { "name": "gd mcgrath", "out": "b harmison", "runs": "5", "minutes": "9", "balls": "12", "4s": "", "6s": "", "sr": "41.66", "home": "england", "away": "australia", "date": "jun 13, 2005", "ground": "southampton", "series": "australia tour of england , scotland", "match_no": "only t20i", "winning_info": "england won 100 runs", "inning": "australia batting", "id": "569aa1f87e655d7e6af61d53" }, { "name": "extras", "out": "(b 1, lb 2, w 1, nb 2)", "runs": "6", "minutes": "", "balls": "", "4s": "", "6s": "", "sr": "", "home": "england", "away": "australia", "date": "jun 13, 2005", "ground": "southampton", "series": "australia tour of england , scotland", "match_no": "only t20i", "winning_info": "england won 100 runs", "inning": "australia batting", "id": "569aa1f87e655d7e6af61d54" }, { "home": "england", "away": "australia", "date": "jun 13, 2005", "ground": "southampton", "series": "australia tour of england , scotland", "match_no": "only t20i", "winning_info": "england won 100 runs", "inning": "australia-batting", "id": "569aa1f87e655d7e6af61d55", "total": "total", "total-d": "(all out; 14.3 overs; 64 mins)", "r": "79", "rpo": "(5.44 runs per over)" }, { "name": "d gough", "runs": "16", "4s": "3", "6s": "", "home": "england", "away": "australia", "date": "jun 13, 2005", "ground": "southampton", "series": "australia tour of england , scotland", "match_no": "only t20i", "winning_info": "england won 100 runs", "inning": "england bowling", "id": "569aa1f87e655d7e6af61d56", "over": "3", "maiden": "", "wickets": "3", "economy": "5.33", "0s": "13" }, { "name": "j lewis", "runs": "24", "4s": "3", "6s": "", "home": "england", "away": "australia", "date": "jun 13, 2005", "ground": "southampton", "series": "australia tour of england , scotland", "match_no": "only t20i", "winning_info": "england won 100 runs", "inning": "england bowling", "id": "569aa1f87e655d7e6af61d57", "over": "4", "maiden": "", "wickets": "4", "economy": "6.00", "0s": "14" }, { "name": "sj harmison", "runs": "13", "4s": "2", "6s": "", "home": "england", "away": "australia", "date": "jun 13, 2005", "ground": "southampton", "series": "australia tour of england , scotland", "match_no": "only t20i", "winning_info": "england won 100 runs", "inning": "england bowling", "id": "569aa1f87e655d7e6af61d58", "over": "2.3", "maiden": "", "wickets": "1", "economy": "5.20", "0s": "9" }, { "name": "mj clarke", "out": "c †jones b lewis", "runs": "", "minutes": "1", "balls": "1", "4s": "", "6s": "", "sr": "0.00", "home": "england", "away": "australia", "date": "jun 13, 2005", "ground": "southampton", "series": "australia tour of england , scotland", "match_no": "only t20i", "winning_info": "england won 100 runs", "inning": "australia batting", "id": "569aa1f87e655d7e6af61d59" }, { "name": "jn gillespie", "out": "c trescothick b collingwood", "runs": "24", "minutes": "18", "balls": "18", "4s": "4", "6s": "", "sr": "133.33", "home": "england", "away": "australia", "date": "jun 13, 2005", "ground": "southampton", "series": "australia tour of england , scotland", "match_no": "only t20i", "winning_info": "england won 100 runs", "inning": "australia batting", "id": "569aa1f87e655d7e6af61d5a" }, { "name": "a flintoff", "runs": "15", "4s": "2", "6s": "", "home": "england", "away": "australia", "date": "jun 13, 2005", "ground": "southampton", "series": "australia tour of england , scotland", "match_no": "only t20i", "winning_info": "england won 100 runs", "inning": "england bowling", "id": "569aa1f87e655d7e6af61d5b", "over": "3", "maiden": "", "wickets": "", "economy": "5.00", "0s": "10" }, { "name": "pd collingwood", "runs": "8", "4s": "", "6s": "", "home": "england", "away": "australia", "date": "jun 13, 2005", "ground": "southampton", "series": "australia tour of england , scotland", "match_no": "only t20i", "winning_info": "england won 100 runs", "inning": "england bowling", "id": "569aa1f87e655d7e6af61d75", "over": "2", "maiden": "", "wickets": "2", "economy": "4.00", "0s": "6" } ]
switch following, think:
runname = namedim.group().reducesum(function(d) { if(d.inning === "england batting") { return number(d.runs); } else { return 0; } }); the problem return undefined in event australia batting, , 15 + undefined evaluates nan.
also: please create working example in future. able eyeball one, there no way me check if solution works. far far more if create working example.
Comments
Post a Comment