I'm trying to do multiple lines graphs into one following Bostock's example on city and temperature.
Example is right here http://bl.ocks.org/mbostock/3884955
Now, I have a tsv file custom made from info from world databank. The format is as follows
Country Name Year GDP Population GDP per Capita Exports Industry
Brazil 2004 663760341880.342 184010283 3607.1915713555 16.4250921582 30.1135838508
Brazil 2005 882185702547.247 186142403 4739.3054367481 15.1283508131 29.27296088
Brazil 2006 1088916819852.94 188134315 5787.9755740091 14.3684508393 28.7527649158
Brazil 2007 1366853244424.28 189996976 7194.0789437843 13.3643803148 27.8112224671
Brazil 2008 1653538618144.8 191765567 8622.7086750397 13.6631968034 27.901606309
Brazil 2009 1620165226993.77 193490922 8373.3397424907 10.9789949015 26.8288327492
Brazil 2010 2143035333258.24 195210154 10978.093553772 10.8715851234 28.0694513261
Brazil 2011 2476652189879.72 196935134 12575.9794079188 11.8891676714 27.5330208705
Brazil 2012 2252664120777.39 198656019 11339.5211084814 12.557350455 26.2886840461
Where I have multiple country inputs for different years. The format is at the suggestion of an answer from another post question here
D3 Getting values from keys using array of objects
This TSV file is meant to graph GDP, Population, etc on separate svg graphs; I put it into one tsv file for convenience. Now, my next step is to extract the countries from my data and graph them as lines. The example has cities as keys in the header line, parsed by d3.keys call. My countries, however, are in one key called Country Name, as shown above. How would I parse my data such that I get one line for each country?
Here is where I'm currently at in terms of coding
//Define Margin Object with properties from the four sides Clockwise
var margin = {top: 20, right: 80, bottom: 30, left: 50};
var dataset;
//Width and Height as inner dimensions of chart area
var width = 960 - margin.left - margin.right;
var height = 500 - margin.top - margin.bottom;
//Define svg
var svg = d3.select("#chart").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 + ")");
var x = d3.scale.linear()
.range([0, width]);
var y = d3.scale.linear()
.range([0, height]);
var color = d3.scale.category10();
var xAxis = d3.svg.axis()
.scale(x)
.orient("bottom");
var yAxis = d3.svg.axis()
.scale(y)
.orient("left");
var line = d3.svg.line()
.interpolate("basis")
.x(function(d) {return x(d.year);})
.y(function(d) {return y(d.GDP);});
d3.tsv("OlympicsData.tsv", function(error, data) {
x.domain(d3.extent(data, function(d) {return d["Year"];}));
y.domain(d3.extent(data, function(d) {return d["GDP"];}));
console.log(d3.min(data, function(d) {return d["Year"];}) + " " + d3.max(data, function(d) {return d["Year"];}));
svg.append("g")
.attr("class", "x axis")
.call(xAxis);
svg.append("g")
.attr("class", "y axis")
.call(yAxis);
});