Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save alemosie/97aa25a5d3df3f1c7d6d4411426852d4 to your computer and use it in GitHub Desktop.
Save alemosie/97aa25a5d3df3f1c7d6d4411426852d4 to your computer and use it in GitHub Desktop.
List of materials you'll want to have prepared for NYC School of Data Open Data APIs session

Under Construction

I'll be updating this page through the course of the day, so please refresh every once in a while.

Preparation

If you'd like to follow along in the live-coding exercise, please take a couple of steps to prepare before our session:

  1. Bring a laptop with an up-to-date modern browser. The latest versions of Chrome or Firefox should work. It likely will work with Chrome or Safari on a tablet like an iPad, but you'll want an attached keyboard to go along with it.
  2. If you don't have a GitHub account, sign up for one: https://github.com
  3. Load up this Plunker code sample and click "Sign in with GitHub" in the upper right. You'll be asked to authorize Plunker, which will allow you to save your work.
  4. Click the "Fork" button in the toolbar to make your own copy

Background & Links

Etc.

  • If you need to cheat at some point, the JavaScript code is below. But please play along :)
$(document).ready(function() {
google.charts.load('current', {packages: ['treemap']});
google.charts.setOnLoadCallback(drawChart);
function drawChart() {
$.ajax({
url: "https://data.cityofnewyork.us/resource/p2mh-mrfv.json",
method: "GET",
datatype: "json",
data: {
"$select" : "address_borough, license_category, count(*) AS total",
"$group" : "address_borough, license_category",
"$where" : "address_borough IS NOT NULL"
}
}).done(function(licenses) {
var table = [
["License Category", "Borough", "Number of Businesses"],
["Global", null, 0]
];
var parents = {};
// Add our license counts
$.each(licenses, function(idx, rec) {
table.push([rec.license_category + " in " + rec.address_borough, rec.address_borough, parseInt(rec.total)]);
parents[rec.address_borough] = true;
});
// Add our parents
$.each(Object.keys(parents), function(idx, parent) {
table.push([parent, "Global", 0]);
});
var data_table = google.visualization.arrayToDataTable(table);
var tree = new google.visualization.TreeMap(document.getElementById('chart'));
tree.draw(data_table, {
minColor: '#7FDBFF',
maxColor: '#0074D9',
headerHeight: 15,
fontColor: 'black',
});
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment