let width = 1000, height = 800, margin = { 'top': 10, 'bottom': 50, 'left': 50, 'right': 10 }, xScale = d3.scaleLinear().range([margin.left, width - margin.right]), yScale = d3.scaleLinear().range([height - margin.bottom, margin.top]), colorScale = d3.schemeCategory20c, regionScale = d3.scaleOrdinal() .domain(['USA', 'Canada', 'South and Central America', 'China', 'Former USSR', 'South and Southeast Asia', 'Pacific Dev. Region', 'North Africa and Middle East', 'Tropical Africa', 'Europe' ]) .range([colorScale[0], colorScale[1], colorScale[2], colorScale[4], colorScale[5], colorScale[6], colorScale[7], colorScale[8], colorScale[9], colorScale[12] ]); let f = d3.format('.2f'); let globalMode = true, globalYScale, localYScale; let tooltip = d3.select('body').append('div').attr('id', 'tooltip').style("display", "none").html(`

`); d3.csv('data.csv', function(data) { data.map(function(d) { d.Global = +d.Global; d.Canada = +d.Canada; d.China = +d.China; d.Europe = +d.Europe; d['Frmr USSR'] = +d['Frmr USSR']; d['Nafrica/Meast'] = +d['Nafrica/Meast']; d['Pac.Dev.Reg'] = +d['Pac.Dev.Reg']; d['S+C America'] = +d['S+C America']; d['S+SE Asia'] = +d['S+SE Asia']; d['Trop.Africa'] = +d['Trop.Africa']; d.USA = +d.USA; d.Year = d3.timeParse("%Y")(d.Year); }); let cum = { 'Global': [], 'Canada': [], 'China': [], 'Europe': [], 'Frmr USSR': [], 'Nafrica/Meast': [], 'Pac.Dev.Reg': [], 'S+C America': [], 'S+SE Asia': [], 'Trop.Africa': [], 'USA': [] }, sum = { 'Global': 0, 'Canada': 0, 'China': 0, 'Europe': 0, 'Frmr USSR': 0, 'Nafrica/Meast': 0, 'Pac.Dev.Reg': 0, 'S+C America': 0, 'S+SE Asia': 0, 'Trop.Africa': 0, 'USA': 0 }; data.forEach(function(d) { sum.Global += d.Global; cum.Global.push(sum.Global); sum.Canada += d.Canada; cum.Canada.push(sum.Canada); sum.China += d.China; cum.China.push(sum.China); sum.Europe += d.Europe; cum.Europe.push(sum.Europe); sum['Frmr USSR'] += d['Frmr USSR']; cum['Frmr USSR'].push(sum['Frmr USSR']); sum['Nafrica/Meast'] += d['Nafrica/Meast']; cum['Nafrica/Meast'].push(sum['Nafrica/Meast']); sum['Pac.Dev.Reg'] += d['Pac.Dev.Reg']; cum['Pac.Dev.Reg'].push(sum['Pac.Dev.Reg']); sum['S+C America'] += d['S+C America']; cum['S+C America'].push(sum['S+C America']); sum['S+SE Asia'] += d['S+SE Asia']; cum['S+SE Asia'].push(sum['S+SE Asia']); sum['Trop.Africa'] += d['Trop.Africa']; cum['Trop.Africa'].push(sum['Trop.Africa']); sum.USA += d.USA; cum.USA.push(sum.USA); }); data.map(function(d, i) { d.cumGlobal = cum.Global[i]; d.cumCanada = cum.Canada[i]; d.cumChina = cum.China[i]; d.cumEurope = cum.Europe[i]; d.cumFrmrUSSR = cum['Frmr USSR'][i]; d.cumNafricaMeast = cum['Nafrica/Meast'][i]; d.cumPacDevReg = cum['Pac.Dev.Reg'][i]; d.cumSCAmerica = cum['S+C America'][i]; d.cumSSEAsia = cum['S+SE Asia'][i]; d.cumTropAfrica = cum['Trop.Africa'][i]; d.cumUSA = cum.USA[i]; }); xScale.domain(d3.extent(data, function(d) { return d.Year; })); yScale.domain(d3.extent(data, function(d) { return d.cumGlobal })); globalYScale = d3.extent(data, function(d) { return d.cumGlobal }); let chart = timeSeries().xScale(xScale).yScale(yScale); d3.select('svg').datum(data).call(chart); });