Skip to content
Browse files

Add age by race

  • Loading branch information...
1 parent 567ea82 commit 37c6b2bf96d9aee72bcdf17ba32e39b90e92407f @JoeGermuska committed Jun 16, 2012
Showing with 38 additions and 11 deletions.
  1. +38 −11 census/js/profile.js
View
49 census/js/profile.js
@@ -2,15 +2,18 @@ $(function(){
function render_profile(data) {
$("#name").html(data.metadata.NAME);
- show_gender_breakdown(data);
+ show_race_breakdown(data);
return data;
}
- function show_gender_breakdown(data) {
+ function show_sex_breakdown(data) {
breakdown = age_breakdown(data, 'PCT012', '2010');
- render_age_chart(breakdown);
+ var series = [
+ {name:'female', data:breakdown.female},
+ {name:'male', data:breakdown.male}];
+ render_age_chart("Population by Sex", series);
}
-
+
function make_padded_key(table,fieldnum) {
fieldnum += ""
while (fieldnum.length < 3) {
@@ -19,6 +22,35 @@ $(function(){
return table + fieldnum;
}
+ function show_race_breakdown(data) {
+ races = {
+ 'hispanic': age_breakdown(data, 'PCT012H'),
+ 'white': age_breakdown(data, 'PCT012I'),
+ 'black': age_breakdown(data, 'PCT012J'),
+ 'asian': age_breakdown(data, 'PCT012L'),
+ 'amerind': age_breakdown(data, 'PCT012K'),
+ 'hawaiian': age_breakdown(data, 'PCT012M'),
+ 'some_other': age_breakdown(data, 'PCT012N'),
+ 'multi': age_breakdown(data, 'PCT012O'),
+ }
+ other_combined = [];
+ for (var i = 0; i < races.multi.length; i++) {
+ other_combined = races['amerind'] + races['hawaiian'] + races['some_other'] + races['multi']
+ }
+ series = [
+ { name: "Hispanic", data: races.hispanic.total},
+ { name: "White", data: races.white.total},
+ { name: "Black", data: races.black.total},
+ { name: "Asian", data: races.asian.total},
+ // { name: "Native American", data: races.amerind.total},
+ // { name: "Hawaiian", data: races.hawaiian.total},
+ // { name: "Some Other Race", data: races.some_other.total},
+ // { name: "Two or more races", data: races.multi.total},
+ { name: "All Other", data: other_combined }
+ ];
+ render_age_chart("Population by Race", series);
+ }
+
function age_breakdown(data,group,year) {
if (!year) { year = '2010' }
// male = PCT012003..102
@@ -30,18 +62,13 @@ $(function(){
breakdown['male'][i] = Number(ire_census.sf1val(data,make_padded_key(group,i+3),year))
breakdown['female'][i] = Number(ire_census.sf1val(data,make_padded_key(group,i+107),year))
breakdown['total'][i] = parseInt(breakdown['male'][i]) + parseInt(breakdown['female'][i])
-
}
return breakdown;
}
// breakdown will be an array of objects
// each object has female, male, total, place
- function render_age_chart(breakdown) {
-
- var series = [
- {name:'female', data:breakdown.female},
- {name:'male', data:breakdown.male}];
+ function render_age_chart(title, series) {
chart = new Highcharts.Chart({
chart: {
@@ -66,7 +93,7 @@ $(function(){
}
},
title: {
- text: 'Population by Gender'
+ text: title
},
subtitle: {
text: ''

0 comments on commit 37c6b2b

Please sign in to comment.
Something went wrong with that request. Please try again.