Skip to content

Instantly share code, notes, and snippets.

View nkabrown's full-sized avatar

Nathan Brown nkabrown

View GitHub Profile
@nkabrown
nkabrown / percentage.js
Created November 11, 2015 01:53
create or convert a chart to display elements with percentages in d3.js
// percentage = value / total * 100
// store total in variable
var total = d3.sum(data, function(d) { return d.values; });
// set upper domain of y-axis not to 100% but to the percentage of the greatest value in your data
y.domain([0, d3.max(data, function(d) { return Math.round((d.values / total) * 100); })]);
// percentage in bar chart
var bars = d3.selectAll('.bar')
.data(data)
@nkabrown
nkabrown / createFilter.js
Last active September 10, 2015 14:13
Reusable function to create data agnostic select filters
// on function call autocreate data agnostic filters
function createFilter(name, data) {
var items = [];
for (i in data) {
items.push(data[i][name]);
}
var list = items.filter(uniqueValues);
list.sort();
$.each(list, function(i, item) {