Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save inv-Ayiba/298244f825681cab0312acd934654968 to your computer and use it in GitHub Desktop.
Save inv-Ayiba/298244f825681cab0312acd934654968 to your computer and use it in GitHub Desktop.
do one scale hopefully thanks test
<div id="one" class ="main">
<div id="two" class = "container">
<div id ="tittle" align="center" >Gross Domestic Product Of The United States</div>
<div class = "holdthing"></div>
<div>
</div>
</div>
/*
req=new XMLHttpRequest();
req.open("GET",'https://raw.githubusercontent.com/freeCodeCamp/ProjectReferenceData/master/GDP-data.json',true);
req.send();
req.onload=function(){
json=JSON.parse(req.responseText);}
*/
const GDP = [243.1, 246.3, 250.1, 260.3, 266.2, 272.9, 279.5, 280.7, 275.4, 271.7, 273.3, 271, 281.2, 290.7, 308.5, 320.3, 336.4, 344.5, 351.8, 356.6, 360.2, 361.4, 368.1, 381.2, 388.5, 392.3, 391.7, 386.5, 385.9, 386.7, 391.6, 400.3, 413.8, 422.2, 430.9, 437.8, 440.5, 446.8, 452, 461.3, 470.6, 472.8, 480.3, 475.7, 468.4, 472.8, 486.7, 500.4, 511.1, 524.2, 525.2, 529.3, 543.3, 542.7, 546, 541.1, 545.9, 557.4, 568.2, 581.6, 595.2, 602.6, 609.6, 613.1, 622.7, 631.8, 645, 654.8, 671.1, 680.8, 692.8, 698.4, 719.2, 732.4, 750.2, 773.1, 797.3, 807.2, 820.8, 834.9, 846, 851.1, 866.6, 883.2, 911.1, 936.3, 952.3, 970.1, 995.4, 1011.4, 1032, 1040.7, 1053.5, 1070.1, 1088.5, 1091.5, 1137.8, 1159.4, 1180.3, 1193.6, 1233.8, 1270.1, 1293.8, 1332, 1380.7, 1417.6, 1436.8, 1479.1, 1494.7, 1534.2, 1563.4, 1603, 1619.6, 1656.4, 1713.8, 1765.9, 1824.5, 1856.9, 1890.5, 1938.4, 1992.5, 2060.2, 2122.4, 2168.7, 2208.7, 2336.6, 2398.9, 2482.2, 2531.6, 2595.9, 2670.4, 2730.7, 2796.5, 2799.9, 2860, 2993.5, 3131.8, 3167.3, 3261.2, 3283.5, 3273.8, 3331.3, 3367.1, 3407.8, 3480.3, 3583.8, 3692.3, 3796.1, 3912.8, 4015, 4087.4, 4147.6, 4237, 4302.3, 4394.6, 4453.1, 4516.3, 4555.2, 4619.6, 4669.4, 4736.2, 4821.5, 4900.5, 5022.7, 5090.6, 5207.7, 5299.5, 5412.7, 5527.4, 5628.4, 5711.6, 5763.4, 5890.8, 5974.7, 6029.5, 6023.3, 6054.9, 6143.6, 6218.4, 6279.3, 6380.8, 6492.3, 6586.5, 6697.6, 6748.2, 6829.6, 6904.2, 7032.8, 7136.3, 7269.8, 7352.3, 7476.7, 7545.3, 7604.9, 7706.5, 7799.5, 7893.1, 8061.5, 8159, 8287.1, 8402.1, 8551.9, 8691.8, 8788.3, 8889.7, 8994.7, 9146.5, 9325.7, 9447.1, 9557, 9712.3, 9926.1, 10031, 10278.3, 10357.4, 10472.3, 10508.1, 10638.4, 10639.5, 10701.3, 10834.4, 10934.8, 11037.1, 11103.8, 11230.1, 11370.7, 11625.1, 11816.8, 11988.4, 12181.4, 12367.7, 12562.2, 12813.7, 12974.1, 13205.4, 13381.6, 13648.9, 13799.8, 13908.5, 14066.4, 14233.2, 14422.3, 14569.7, 14685.3, 14668.4, 14813, 14843, 14549.9, 14383.9, 14340.4, 14384.1, 14566.5, 14681.1, 14888.6, 15057.7, 15230.2, 15238.4, 15460.9, 15587.1, 15785.3, 15973.9, 16121.9, 16227.9, 16297.3, 16440.7, 16526.8, 16727.5, 16957.6, 16984.3, 17270, 17522.1, 17615.9, 17649.3, 17913.7, 18064.7] ;
const years = [1947, 1948, 1949, 1950, 1951, 1952, 1953, 1954, 1955, 1956, 1957, 1958, 1959, 1960, 1961, 1962, 1963, 1964, 1965, 1966, 1967, 1968, 1969, 1970, 1971, 1972, 1973, 1974, 1975, 1976, 1977, 1978, 1979, 1980, 1981, 1982, 1983, 1984, 1985, 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015] ;
const years3 = ["1947-01-01", "1947-04-01", "1947-07-01", "1947-10-01", "1948-01-01", "1948-04-01", "1948-07-01", "1948-10-01", "1949-01-01", "1949-04-01", "1949-07-01", "1949-10-01", "1950-01-01", "1950-04-01", "1950-07-01", "1950-10-01", "1951-01-01", "1951-04-01", "1951-07-01", "1951-10-01", "1952-01-01", "1952-04-01", "1952-07-01", "1952-10-01", "1953-01-01", "1953-04-01", "1953-07-01", "1953-10-01", "1954-01-01", "1954-04-01", "1954-07-01", "1954-10-01", "1955-01-01", "1955-04-01", "1955-07-01", "1955-10-01", "1956-01-01", "1956-04-01", "1956-07-01", "1956-10-01", "1957-01-01", "1957-04-01", "1957-07-01", "1957-10-01", "1958-01-01", "1958-04-01", "1958-07-01", "1958-10-01", "1959-01-01", "1959-04-01", "1959-07-01", "1959-10-01", "1960-01-01", "1960-04-01", "1960-07-01", "1960-10-01", "1961-01-01", "1961-04-01", "1961-07-01", "1961-10-01", "1962-01-01", "1962-04-01", "1962-07-01", "1962-10-01", "1963-01-01", "1963-04-01", "1963-07-01", "1963-10-01", "1964-01-01", "1964-04-01", "1964-07-01", "1964-10-01", "1965-01-01", "1965-04-01", "1965-07-01", "1965-10-01", "1966-01-01", "1966-04-01", "1966-07-01", "1966-10-01", "1967-01-01", "1967-04-01", "1967-07-01", "1967-10-01", "1968-01-01", "1968-04-01", "1968-07-01", "1968-10-01", "1969-01-01", "1969-04-01", "1969-07-01", "1969-10-01", "1970-01-01", "1970-04-01", "1970-07-01", "1970-10-01", "1971-01-01", "1971-04-01", "1971-07-01", "1971-10-01", "1972-01-01", "1972-04-01", "1972-07-01", "1972-10-01", "1973-01-01", "1973-04-01", "1973-07-01", "1973-10-01", "1974-01-01", "1974-04-01", "1974-07-01", "1974-10-01", "1975-01-01", "1975-04-01", "1975-07-01", "1975-10-01", "1976-01-01", "1976-04-01", "1976-07-01", "1976-10-01", "1977-01-01", "1977-04-01", "1977-07-01", "1977-10-01", "1978-01-01", "1978-04-01", "1978-07-01", "1978-10-01", "1979-01-01", "1979-04-01", "1979-07-01", "1979-10-01", "1980-01-01", "1980-04-01", "1980-07-01", "1980-10-01", "1981-01-01", "1981-04-01", "1981-07-01", "1981-10-01", "1982-01-01", "1982-04-01", "1982-07-01", "1982-10-01", "1983-01-01", "1983-04-01", "1983-07-01", "1983-10-01", "1984-01-01", "1984-04-01", "1984-07-01", "1984-10-01", "1985-01-01", "1985-04-01", "1985-07-01", "1985-10-01", "1986-01-01", "1986-04-01", "1986-07-01", "1986-10-01", "1987-01-01", "1987-04-01", "1987-07-01", "1987-10-01", "1988-01-01", "1988-04-01", "1988-07-01", "1988-10-01", "1989-01-01", "1989-04-01", "1989-07-01", "1989-10-01", "1990-01-01", "1990-04-01", "1990-07-01", "1990-10-01", "1991-01-01", "1991-04-01", "1991-07-01", "1991-10-01", "1992-01-01", "1992-04-01", "1992-07-01", "1992-10-01", "1993-01-01", "1993-04-01", "1993-07-01", "1993-10-01", "1994-01-01", "1994-04-01", "1994-07-01", "1994-10-01", "1995-01-01", "1995-04-01", "1995-07-01", "1995-10-01", "1996-01-01", "1996-04-01", "1996-07-01", "1996-10-01", "1997-01-01", "1997-04-01", "1997-07-01", "1997-10-01", "1998-01-01", "1998-04-01", "1998-07-01", "1998-10-01", "1999-01-01", "1999-04-01", "1999-07-01", "1999-10-01", "2000-01-01", "2000-04-01", "2000-07-01", "2000-10-01", "2001-01-01", "2001-04-01", "2001-07-01", "2001-10-01", "2002-01-01", "2002-04-01", "2002-07-01", "2002-10-01", "2003-01-01", "2003-04-01", "2003-07-01", "2003-10-01", "2004-01-01", "2004-04-01", "2004-07-01", "2004-10-01", "2005-01-01", "2005-04-01", "2005-07-01", "2005-10-01", "2006-01-01", "2006-04-01", "2006-07-01", "2006-10-01", "2007-01-01", "2007-04-01", "2007-07-01", "2007-10-01", "2008-01-01", "2008-04-01", "2008-07-01", "2008-10-01", "2009-01-01", "2009-04-01", "2009-07-01", "2009-10-01", "2010-01-01", "2010-04-01", "2010-07-01", "2010-10-01", "2011-01-01", "2011-04-01", "2011-07-01", "2011-10-01", "2012-01-01", "2012-04-01", "2012-07-01", "2012-10-01", "2013-01-01", "2013-04-01", "2013-07-01", "2013-10-01", "2014-01-01", "2014-04-01", "2014-07-01", "2014-10-01", "2015-01-01", "2015-04-01", "2015-07-01"];
quarters = [1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3];
let tooltip = d3
.select("body")
.append("div")
.attr("class", "tooltip")
.attr("id", "tooltip")
.style("opacity", 0);
const w = 1300;
const h = 715;
// Padding between the SVG canvas boundary and the plot
const padding = 30;
const hScale = d3.scaleLinear()
.domain([243.1,18064.7])
.range([padding,h-padding])
const xScale = d3.scaleLinear()
.domain([1947, 2015])
.range([padding, w - padding]);
var scaledGDP = [];
var gdpMin = d3.min(GDP);
var gdpMax = d3.max(GDP);
var linearScale = d3.scaleLinear()
.domain([0, gdpMax])
.range([0, h]);
scaledGDP = GDP.map(function(item) {
return linearScale(item);
});
const yScale = d3.scaleLinear()
.domain([243.1,18064.7])
.range([padding,h-padding])
const yScale2 = d3.scaleLinear()
.domain([243.1,18064.7])
.range([h-padding,padding])
const svg = d3.select("body")
.append("svg")
.attr("width", '100%')
.attr("height", h)
;
svg.selectAll("rect")
.data(scaledGDP)
.enter()
.append("rect")
.attr("x", (d, i) => (i * 4.5)+40)
.attr("y", (d,i) => h - hScale(GDP[i]))
.attr("width", 2.8)
.attr("height", (d,i) => hScale(GDP[i])-26)
.attr("fill", "navy")
.attr("class","bar")
.on("mouseover", function(d,i) {
tooltip
.transition()
.duration(200)
.style("opacity", 0.9);
tooltip
.html((testarr[i]/1000).toFixed(2) +" Trillion " + years2[i] + " " + quarters[i] + "Q" )
.style("left", d3.event.pageX + 20 + "px")
.style("top", d3.event.pageY + 20 + "px");
// tooltip.attr("data-date", d[0]);
})
.on("mouseout", function(d) {
tooltip
.transition()
.duration(400)
.style("opacity", 0);
});
svg.append('text')
.attr('transform', 'rotate(-90)')
.attr('x', -200)
.attr('y', 80)
.attr("id","title")
.text('Gross Domestic Product');
const xAxis = d3.axisBottom(xScale);
svg.append("g")
.attr("transform", "translate(5, " + (h - 25) + ")")
.attr("id","x-axis")
.call(xAxis);
const yAxis = d3.axisLeft(yScale2);
svg.append("g")
.attr("transform", "translate(" + ( padding+5) + ",5)")
.attr("id","y-axis")
.call(yAxis) ;
svg.selectAll("rect")
.attr("data-date", (d, i) => years3[i])
.attr("data-gdp", (d, i) => GDP[i] );
console.log(GDP) ;
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/4.2.2/d3.min.js"></script>
svg {
background-color: #82b9e8;
}
.tooltip
{
position: absolute;
text-align: center;
width: 60px;
height: auto;
padding: 2px;
font: 12px sans-serif;
background: lavender;
border: 0px;
border-radius: 8px;
pointer-events: none;
}
.bar:hover {
fill: red;}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment