Reputation:
I have a data like this
Sl.No,Sex,Age_band,TYPE of Mesh,Type of Surgery 16,M,0-25,PHS,UL Inguinal 20,M,0-25,PHS,UL Inguinal 90,M,0-25,UHSL,UL Inguinal 95,M,0-25,UHSL,UL Inguinal 117,M,0-25,UHSL,UL Inguinal 119,M,0-25,UHSL,UL Inguinal 32,M,0-25,Ultrapro,Incisional 14,M,26-35,PHS,UL Inguinal 18,M,26-35,PHS,UL Inguinal
I am trying to plot a composite chart and my code is
var mFilteredData = crossfilter(mData);
var mDimension = mFilteredData.dimension(dc.pluck("Age_band"));
var mGroup = mDimension.group().reduceCount(dc.pluck("TYPE of Mesh"));
var mGroup1 = mDimension.group().reduceCount(dc.pluck("Type of Surgery"));
var chart = dc.compositeChart(".chart");
chart
.width(400)
.height(300)
.yAxisLabel("User Count")
.renderHorizontalGridLines(true)
.dimension(mDimension)
.x(d3.scale.ordinal())
.xUnits(dc.units.ordinal)
.compose([
dc.barChart(chart)
.centerBar(true)
.gap(100)
.colors('red')
.group(mGroup)
,
dc.barChart(chart)
.centerBar(true)
.gap(100)
.colors('blue')
.group(mGroup1)])
.brushOn(false)
.render();
But I am getting this errror
Uncaught TypeError: Cannot call method 'all' of undefined
Upvotes: 3
Views: 2538
Reputation: 4010
I also had the same issue. After some digging around in the dc source code I saw that if you have an ordinal x scale, the chart calls it's groups all() function (not completely sure why, but it seems to be using the data for the x axis domain). By adding a group to your composite chart you will solve this issue. Like so:
dc.compositeChart(".chart")
.width(400)
.height(300)
.yAxisLabel("User Count")
.renderHorizontalGridLines(true)
.dimension(mDimension)
.group(mGroup)
.x(d3.scale.ordinal())
.xUnits(dc.units.ordinal)
Upvotes: 4