The following produces a bar chart that shows 4 people on the x axis and the number of times they show up on the y-axis.However I'd like to filter this data to only count the owner's if they have an ID of "A."
Also, would it be possible to apply this filter with a button or an onClick handler so that the data is only filtered for ID of "A" upon pressing the button.
See code below and jsfiddle here: http://jsfiddle.net/chrisguzman/y9xt2/
var data = [{
Owner: "Alyssa",
ID: "A"
}, {
Owner: "Alyssa",
ID: "A"
}, {
Owner: "Alyssa",
ID: "A"
}, {
Owner: "Alyssa",
ID: "A"
}, {
Owner: "Alyssa",
ID: "B"
}, {
Owner: "Bob",
ID: "A"
}, {
Owner: "Bob",
ID: "A"
}, {
Owner: "Bob",
ID: "C"
}, {
Owner: "Bob",
ID: "C"
}, {
Owner: "Bob",
ID: "C"
}, {
Owner: "Bob",
ID: "C"
}, {
Owner: "Bob",
ID: "C"
}, {
Owner: "Bob",
ID: "D"
}, {
Owner: "Joe",
ID: "A"
}, {
Owner: "Joe",
ID: "A"
}, {
Owner: "Joe",
ID: "D"
}, {
Owner: "Joe",
ID: "D"
}, {
Owner: "Joe",
ID: "E"
}];
var ndx = crossfilter(data);
var XDimension = ndx.dimension(function (d) {
return d.Owner;
});
var YDimension = XDimension.group().reduceCount(function (d) {
return d.Owner;
});
dc.barChart("#Chart")
.width(480).height(300)
.dimension(XDimension)
.group(YDimension)
.centerBar(true)
.gap(56)
.x(d3.scale.ordinal().domain(XDimension))
.xUnits(dc.units.ordinal)
.xAxisLabel("Market Developer")
.yAxisLabel("Unique Counts")
.elasticY(true)
.xAxis().tickFormat(function (v) {
return v;
});
dc.renderAll();