var table, r, yAxisData, xAxisData, maxLabel, minLabel, maxValue, minValue, firstMajorRow, temp, interval, major; function preload() { table = loadTable('graduates.csv', 'csv'); } function setup() { createCanvas(1000, 1000); xAxisData = 22; // Column number of the x axis nominal value (Type of Major) yAxisData = 2; // Column number of the y axis quantitative value (Asians) major = 'Chemistry'; // Change this variable to whatever major you would like data from. allMajorRows = []; for (r = 1 ; r < table.getRowCount() ; r++) { if (table.getString(r, 22) == major) { append(allMajorRows, r); } } maxValue = int(table.getString(allMajorRows[0], yAxisData)); minValue = maxValue; for (r = 0 ; r < allMajorRows.length ; r++) { temp = int(table.getString(allMajorRows[r], yAxisData)); if (temp > maxValue) { maxValue = temp; } else if (temp < minValue) { minValue = temp; } } minLabel = int(((minValue - minValue % 10) / 10 - 1) * 10); print(maxValue); print(minValue); interval = 10; while (true) { if (interval * 9 + minLabel > int(maxValue)) { maxLabel = interval * 9 + minLabel; break; } interval += 10; } print(maxLabel); print(minLabel); } function draw() { background(255); textSize(8); var x, y; y = minLabel; for (x = 615 ; x > 15 ; x -= 60) { text(y, 35, x, 40, 50); line(73, x, 77, x); y += interval; } x = 85; var mappedValue; for (r = 0 ; r < allMajorRows.length - 1 ; r++) { temp = int(table.getString(allMajorRows[r], yAxisData)); mappedValue = map(temp, minLabel, maxLabel, 0, 540, true); text(table.getString(allMajorRows[r], 49), x, 685, 45, 150); line(x, 615 - mappedValue, x + 75, 615 - map(int(table.getString(allMajorRows[r + 1], yAxisData)), minLabel, maxLabel, 0, 540, true)); if (dist(mouseX, mouseY, x, 615 - mappedValue) < 5) { text(temp, x - 5, 605 - mappedValue); } x += 75; } if (dist(mouseX, mouseY, x, 615 - map(int(table.getString(allMajorRows[r], yAxisData)), minLabel, maxLabel, 0, 540, true)) < 5) { text(table.getString(allMajorRows[r], yAxisData), x - 5, 605 - map(int(table.getString(allMajorRows[r], yAxisData)), minLabel, maxLabel, 0, 540), true); } // Final year at end of graph text(table.getString(allMajorRows[r], 49), x, 685, 45, 150); // Makes the edge of graph slightly to the right; x += 15; fill(0); // Draws the lines for the axes line(75, 65, 75, 675); line(75, 65, x, 65); line(75, 675, x, 675); line(x, 65, x, 675); // Labels the axes with the header from the appropriate column number textSize(12); text("Number of " + table.getString(0, yAxisData), 10, 625, 50, 120); text(table.getString(0, xAxisData), 150, 725, 200, 50); // Prints the built title var title = "Number of " + table.getString(0, yAxisData) + " With " + major + " " + table.getString(0, xAxisData); textSize(20); text(title, 150, 25, 400, 50); }