Skip to content

Instantly share code, notes, and snippets.

@exp0nge
Last active May 26, 2016 02:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save exp0nge/4d7059c68828420b9fdeaec21c085fe1 to your computer and use it in GitHub Desktop.
Save exp0nge/4d7059c68828420b9fdeaec21c085fe1 to your computer and use it in GitHub Desktop.
step-2
$(document).ready(function () {
d3.json('data.json', function (data) {
var ndx = crossfilter(data); // Tell Crossfilter what data we want to filter.
//defaultDim is for the total # of defaulters ticker.
var defaultDim = ndx.dimension(function (d) {
return d['default payment next month'];
});
//genderDim filters based on gender. The function will iterate over the 30,000 records returning either Male, Female, or Unknown every time.
// We can then use dc.js to tally those up.
var genderDim = ndx.dimension(function (d) { //notice the parameter, since we told Crossfilter what our data is, we can just get it in our callbacks
var sex = d['SEX'];
if (sex === 1) {
return 'Male';
} else if (sex === 2) {
return 'Female';
} else {
return 'Unknown';
}
});
//marriageDim filters based on marriage status.
var marriageDim = ndx.dimension(function (d) {
var status = d['MARRIAGE'];
if (status === 1) {
return 'Married';
} else if (status == 2) {
return 'Single';
} else if (status === 3) {
return 'Others';
} else {
return 'Unknown';
}
});
//ageDefaultersDim filters on age.
var ageDefaultersDim = ndx.dimension(function (d) {
return d['AGE'];
});
//limitDefaultersDim filters on total credit given to an individual.
var limitDefaultersDim = ndx.dimension(function (d) {
return d['LIMIT_BAL'];
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment