Last active
October 19, 2023 01:38
Revisions
-
mdml revised this gist
Jan 8, 2014 . 2 changed files with 7 additions and 9 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -75,17 +75,15 @@ }; })); // Find the value of the day with highest total value var maxDateVal = d3.max(data, function(d){ var vals = d3.keys(d).map(function(key){ return key !== "date" ? d[key] : 0 }); return d3.sum(vals); }); // Set domains for axes x.domain(d3.extent(data, function(d) { return d.date; })); y.domain([0, maxDateVal]) var browser = svg.selectAll(".browser") .data(browsers) LoadingSorry, something went wrong. Reload?Sorry, we cannot display this file.Sorry, this file is invalid so it cannot be displayed. -
mdml revised this gist
Jan 7, 2014 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
LoadingSorry, something went wrong. Reload?Sorry, we cannot display this file.Sorry, this file is invalid so it cannot be displayed. -
mdml revised this gist
Jan 7, 2014 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -60,7 +60,7 @@ .append("g") .attr("transform", "translate(" + margin.left + "," + margin.top + ")"); d3.csv("data.csv", function(error, data) { color.domain(d3.keys(data[0]).filter(function(key) { return key !== "date"; })); data.forEach(function(d) { d.date = parseDate(d.date); -
mdml revised this gist
Jan 7, 2014 . 1 changed file with 4 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,4 @@ date,Kermit,piggy,Gonzo,fuzzy,hogthrob,animal,floyd,Gabriel,Beaker,scooter,statler,waldorf,slim,sam 13-Oct-31,113.44,435.15,19.57,60.55,53.02,268.28,87.34,1.98,0,31.68,0,21.59,4.82,11.31 13-Nov-30,109.86,506.85,18.97,58.77,388.37,131.48,85.34,1.98,0,48.50,0,21.59,4.70,11.31 13-Dec-31,113.46,644.88,19.57,60.57,669.47,0,87.46,1.98,0,80.97,0,21.59,4.82,11.43 -
mdml created this gist
Jan 7, 2014 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1 @@ Example of stacked area charts --based off of [this gist](http://bl.ocks.org/mbostock/3885211#) -- addressing this [SO question](http://stackoverflow.com/questions/20973599/novice-d3-stacked-area-graph). This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,117 @@ <!DOCTYPE html> <meta charset="utf-8"> <style> body { font: 10px sans-serif; } .axis path, .axis line { fill: none; stroke: #000; shape-rendering: crispEdges; } .browser text { text-anchor: end; } </style> <body> <script src="http://d3js.org/d3.v3.js"></script> <script> var margin = {top: 20, right: 20, bottom: 30, left: 50}, width = 960 - margin.left - margin.right, height = 500 - margin.top - margin.bottom; var parseDate = d3.time.format("%y-%b-%d").parse; //formatPercent = d3.format(".0%"); var x = d3.time.scale() .range([0, width]); var y = d3.scale.linear() .range([height, 0]); var color = d3.scale.category20(); var xAxis = d3.svg.axis() .scale(x) .orient("bottom"); var yAxis = d3.svg.axis() .scale(y) .orient("left") //.tickFormat(formatPercent); var area = d3.svg.area() .x(function(d) { return x(d.date); }) .y0(function(d) { return y(d.y0); }) .y1(function(d) { return y(d.y0 + d.y); }); var stack = d3.layout.stack() .values(function(d) { return d.values; }); var svg = d3.select("body").append("svg") .attr("width", width + margin.left + margin.right) .attr("height", height + margin.top + margin.bottom) .append("g") .attr("transform", "translate(" + margin.left + "," + margin.top + ")"); d3.csv("http://cl.ly/2q2P260m2f3M/data.csv", function(error, data) { color.domain(d3.keys(data[0]).filter(function(key) { return key !== "date"; })); data.forEach(function(d) { d.date = parseDate(d.date); }); var browsers = stack(color.domain().map(function(name) { return { name: name, values: data.map(function(d) { return {date: d.date, y: d[name] * 1}; }) }; })); // Extract all data points (ignoring dates) var dataPoints = []; data.forEach(function(d){ d3.keys(d).forEach(function(n){ if (n != "date") dataPoints.push( d[n] * 1. ); }); }) // Set domains for axes x.domain(d3.extent(data, function(d) { return d.date; })); y.domain(d3.extent(dataPoints)) var browser = svg.selectAll(".browser") .data(browsers) .enter().append("g") .attr("class", "browser"); browser.append("path") .attr("class", "area") .attr("d", function(d) { return area(d.values); }) .style("fill", function(d) { return color(d.name); }); browser.append("text") .datum(function(d) { return {name: d.name, value: d.values[d.values.length - 1]}; }) .attr("transform", function(d) { return "translate(" + x(d.value.date) + "," + y(d.value.y0 + d.value.y / 2) + ")"; }) .attr("x", -6) .attr("dy", ".35em") .text(function(d) { return d.name; }); svg.append("g") .attr("class", "x axis") .attr("transform", "translate(0," + height + ")") .call(xAxis); svg.append("g") .attr("class", "y axis") .call(yAxis); }); </script>