Tuesday 15 January 2013

javascript - dc.js chart groups not updating with correct values on charts after click on a parent chart -



javascript - dc.js chart groups not updating with correct values on charts after click on a parent chart -

my issue here have crossfilter grouping cut down function calculating savings, when filter applied on chart, seems not pass right filter across. have similar case working example.

i have created 2 jsbin's out of 1 of them has right behavior.

i have info 2 years in case 2010 , 2014. in savings(not working) chart carrier pie chart doesn't filter year whereas in difot(working) chart.

the links : difot(working) : http://jsbin.com/bagohavehu/2/edit savings (not working expected) : http://jsbin.com/yudametulo/2/edit

thanks lot time , effort.

regards, animesh

to track these calculation problems down, need utilize debugger , set breakpoints in reduction functions or in draw functions see reduced values ended with.

i find using browser's debugger hard (impossible?) in jsbin, have 1 time again pasted code 2 jsfiddles:

parsefloat version: http://jsfiddle.net/gordonwoodhull/aqhlv0qc/

parseint version: http://jsfiddle.net/gordonwoodhull/9bnejplx/1/

now, set breakpoint in chart.redraw (dc.js:1139) see values it's trying plot on clicking slice.

the first time breakpoint nail isn't interesting, because it's yearly chart clicked on, sec nail carrier chart, reveals lot. printing _chart.group().all() parseint version:

now, parsefloat version:

since calculations come out exact int version, end 1 - 0/0 === nan, , somewhere along way dc.js or d3.js silently forces nan zero.

but since float calculations never exact, end 1 - 0/-3e-15 === 1.

you want avoid dividing zero, or close zero, adding check in reduction function produces (i think) desired result:

var grouping = dim.group().reduce( function(p,v){ p.current += parsefloat(v.currentprice); p.compare += parsefloat(v.compareprice); if(math.abs(p.compare) > 0.01) { p.savings = p.current/p.compare; p.result = 1-p.savings; } else p.result = 0; homecoming p; }, function(p,v){ p.current -= parsefloat(v.currentprice); p.compare -= parsefloat(v.compareprice); if(math.abs(p.compare) > 0.01) { p.savings = p.current/p.compare; p.result = 1-p.savings; } else p.result = 0; homecoming p; }, function(){return { current: 0, compare: 0,savings:0, result:0};} );

working version (i think): http://jsfiddle.net/gordonwoodhull/y2sf7y18/1/

javascript dc.js crossfilter

No comments:

Post a Comment