Last active
May 26, 2016 02:50
-
-
Save exp0nge/4d7059c68828420b9fdeaec21c085fe1 to your computer and use it in GitHub Desktop.
step-2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(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