xxxxxxxxxx
61
var url;
var cultures = [];
function preload() {
// Loading data from the API.
// *** Insert your API key here: ***
var API_KEY = 'bed2195f-e7c6-40e5-b425-5c60a76b4af2';
var query = 'culture';
var params = '&size=100';
url = 'https://api.harvardartmuseums.org/'+query+'?apikey='+API_KEY+params;
loadJSON(url, gotResponse);
}
function setup() {
createCanvas(900, 900);
// ---------------------------------------------
// Using the data from the cultures[] array, make a histogram
// showing the number of objects in Harvard's collection for each culture.
// ---------------------------------------------
// Hint: You might want to start by just displaying a list of all cultures' name
// and number of associated objects. Remember to use the dot notation for
// key/value pairs. You can look at the whole cultures array in the console
// below with this line:
//console.log(cultures);
textSize(8);
//cultures.length
for (i = 0; i<100; i++){
//console.log(cultures[i].name);
//console.log(cultures[i].objectcount);
rect(0, 9*i, cultures[i].objectcount, 9)
text(cultures[i].name, cultures[i].objectcount+5, 9*i+8);
}
}
function gotResponse(response) {
// This API is limited to 100 items per page. This code determines how many
// pages there are, calls up each page, and loads each page's JSON into memory.
var totalPages = response.info.pages;
for (var currentPage = 1; currentPage <= totalPages; currentPage += 1) {
url = url+'&page='+currentPage;
loadJSON(url, gotPages);
}
}
function gotPages(response) {
// For each page of results, this code adds the results to cultures[] array.
cultures = cultures.concat(response.records);
}