In my dataset I have 4 columns which are formatted like this:
Basically we are following patients throughout the time and as soon as the event occurs, all the values from that timeslot till the end will be true. So to see the percentage of survival at a certain time I need to see the amount of people that have value 'false' at that moment in time I am trying to get this into a linechart (dc.js) where the x-as represent time and y-axis represents percentage of dataset that contains 'false'(at that time)
I tried first doing this with 4 different dimensions, 1 for each field. This did not work correctly.
I assume i need to get these 4 fields into one dimension.
i have a printfilter function to check if my dimensions and groups work correctly:
function print_filter(filter){
var f=eval(filter);
if (typeof(f.length) != "undefined") {}else{}
if (typeof(f.top) != "undefined") {f=f.top(Infinity);}else{}
if (typeof(f.dimension) != "undefined") {f=f.dimension(function(d) { return "";}).top(Infinity);}else{}
console.log(filter+"("+f.length+") = "+JSON.stringify(f).replace("[","[\n\t").replace(/}\,/g,"},\n\t").replace("]","\n]"));
};
When i call this filter on myDimension.group.reduceCount() i want the output to be as following:
[{0 : 100}, {13: 48}, {26 : 60}, {52: 72}]
the first item in the object is the time in weeks and the second item is the percentage of people with false at that time
How should i set up the dimensions and groups to achieve this output?
UPDATE: tried using the following code which did not work either:
var recDim = {
x0: cf1.dimension(function(d){return d.recidiefNa0;}),
x13: cf1.dimension(function(d){return d.recidiefNa13;}),
x26: cf1.dimension(function(d){return d.recidiefNa26;}),
x52: cf1.dimension(function(d){return d.recidiefNa52;})
};
var recGroup = {
0: recDim.x0.group(),
13: recDim.x13.group(),
26: recDim.x26.group(),
52: recDim.x52.group()
} ;
print_filter(recGroup);
UPDATE 2 : I tried using 4 dimensions instead and making a composite linechart. This is the current code. It calculates and renders the datapoints at the right place put because its 4 different chart is doenst show the correct line
var recDim0 = cf1.dimension(function(d){ return [d.recidiefNa0]});
var recDim13 = cf1.dimension(function(d){return [d.recidiefNa13]});
var recDim26 = cf1.dimension(function(d){return [d.recidiefNa26]});
var recDim52 = cf1.dimension(function(d){return [d.recidiefNa52]});
var recGroup0 = recDim0.group();
var recGroup13 = recDim13.group();
var recGroup26 = recDim26.group();
var recGroup52 = recDim52.group();
var scChart = dc.compositeChart("#scStepChart");
scChart
.width(600)
.height(400)
.x(d3.scale.linear().domain([0,52]))
.y(d3.scale.linear().domain([0,100]))
.clipPadding(10)
.brushOn(false)
.xAxisLabel("tijd in weken")
.yAxisLabel("percentage vrij van residu/recidief")
.compose([
dc.lineChart(scChart)
.dimension(recDim0)
.group(recGroup0)
.renderDataPoints(true)
.renderTitle(false)
.keyAccessor(function(d) {return 0;})
.valueAccessor(function(d){return d.value/cf1.groupAll().reduceCount().value()*100;}),
dc.lineChart(scChart)
.dimension(recDim13)
.group(recGroup13)
.renderDataPoints(true)
.renderTitle(false)
.colors(['blue'])
.keyAccessor(function(d){return 13;})
.valueAccessor(function(d){return d.value/cf1.groupAll().reduceCount().value()*100;}),
dc.lineChart(scChart)
.dimension(recDim26)
.group(recGroup26)
.renderDataPoints(true)
.renderTitle(false)
.colors(['blue'])
.keyAccessor(function(d){return 26;})
.valueAccessor(function(d){return d.value/cf1.groupAll().reduceCount().value()*100;}),
dc.lineChart(scChart)
.dimension(recDim52)
.group(recGroup52)
.renderDataPoints(true)
.renderTitle(false)
.colors(['blue'])
.keyAccessor(function(d){return 52;})
.valueAccessor(function(d){return d.value/cf1.groupAll().reduceCount().value()*100})
])
.xAxis().ticks(4);
scChart.render();
This is the result , as you can see the line isn't showing correctly.
http://postimg.org/image/gitdw1yj9/
In the comments are the links for JSFiddle and CodePen