Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                
<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <meta name="description" content="Quote Machine">
  <meta name="keywords" content="HTML,CSS,XML,JavaScript,JQuery,Bootstrap,Ajax">
  <meta name="author" content="Cesar Gomez">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">

  <link href="https://fonts.googleapis.com/css?family=Noto+Serif+SC:400,600,700" rel="stylesheet"><script src="https://cdn.freecodecamp.org/testable-projects-fcc/v1/bundle.js"></script>

</head>
<body>
  <div class="text-center">
     <h1 id="title">DATA CHART</h1>
  </div>
  <div class="row">
    <div class="col">
            <div id="graph"> </div>
                            <div  class="freeIcon text-center">
        <i class="fab fa-free-code-camp"></i>
      </div>

    </div>
    <div class="col">
      <div class="text-center" id="userTitle">
        <h3>User Stories to Complete</h3>
      </div>
      <ul>
        <li>My chart should have a title with a corresponding id="title"</li>
        <li>My chart should have a g element x-axis with a corresponding id="x-axis".</li>
        <li>My chart should have a g element y-axis with a corresponding id="y-axis"</li>
        <li>Both axes should contain multiple tick labels, each with the corresponding class="tick"</li>
        <li>My chart should have a rect element for each data point with a corresponding class="bar" displaying the data</li>
        <li> Each bar should have the properties data-date and data-gdp containing date and GDP values</li>
        <li>The bar elements' data-date properties should match the order of the provided data</li>
        <li>The bar elements' data-gdp properties should match the order of the provided data</li>
        <li>Each bar element's height should accurately represent the data's corresponding GDP</li>
         <li>The data-date attribute and its corresponding bar element should align with the corresponding value on the x-axis</li>
         <li>The data-gdp attribute and its corresponding bar element should align with the corresponding value on the y-axis</li>
         <li>I can mouse over an area and see a tooltip with a corresponding id="tooltip" which displays more information about the area</li>
        <li>My tooltip should have a data-date property that corresponds to the data-date of the active area</li>
      </ul>


    </div>



</body>



              
            
!

CSS

              
                body{
  background-color: #2f2fa2;
     position:relative;
}

#graph {
  margin-top: 40px;
  text-align:center;
}

#title{
  color: #fff;
  margin-bottom:50px;
  border-bottom: 5px;
}

.bar {
  fill: #f64c72;

}

.active{
  fill:red;
}

div.tooltip {		
    position:absolute;
    text-align: center;			
    width: 60px;					
    height: 48px;					
    padding: 2px;				
    font: 12px sans-serif;		
    background: lightsteelblue;	
    border: 0px;		
    border-radius: 8px;			
    pointer-events: none;
    fill:red;
}
ul {
  color: #fff;
  font-weight:600;
}

li{
  padding: 5px;
}

.freeIcon{
  font-size: 95px;
  color: #fff;
}

#userTitle{
  margin-bottom: 10px;
  color: #99738e;
}



              
            
!

JS

              
                

let value = [];
let dates = []

const width = 700;
const height = 530;



d3.json("https://raw.githubusercontent.com/freeCodeCamp/ProjectReferenceData/master/GDP-data.json").then((data) => {
  let datas = data.data;
  datas.forEach(function(setData){
    dates.push(new Date (setData[0]))
    value.push((setData[1]))
    // value.splice(55, value.length)
  })
console.log(value)

const svg = d3.select("#graph")
                .append("svg")
                .attr("width",width)
                .attr("height", height);

  const sameDate = d3.timeFormat("%Y-%m-%d")	

const xScale = d3.scaleTime()
                  .domain([d3.min(dates), d3.max(dates)])
                  .range([0 , width - 80]);

const x_axis = d3.axisBottom()
                 .scale(xScale)

const yAxis = d3.scaleLinear()
                .domain([0, d3.max(value)])
                .range([height , 0])

const y_axis = d3.axisLeft()
                 .scale(yAxis)

const scaleGross = d3.scaleLinear()
                     .domain([0, d3.max(value)])
                     .range([0, height])

const gdp = value.map(function(item){
  return scaleGross(item)
})


let xAxisTranslate = height - 30;
const yAxisTranslate = 0 - 30;
  
      svg.append("g")
            .attr("transform", "translate(50, " + xAxisTranslate  +")")
            .attr("id","x-axis")
            .call(x_axis)
            .style("color","white")
    
      svg.append("g")
         .attr("transform","translate(50,"+ yAxisTranslate +")")
         .attr("id","y-axis")
         .call(y_axis)
         .style("color","white")
  

  
let div = d3.select("body").append("div")	
            .attr("class", "tooltip")
            .attr("id", "tooltip")
             .style("opacity", 0);
  
      svg.selectAll("rect")
         .data(gdp)
         .enter()
         .append("rect")
         
         .attr("data-date", function(d,i) {
            
            return datas[i][0]
         })
         .attr("data-gdp", function(d,i) {
            return datas[i][1]
         })
         .attr('x', function(d, i) {
           return xScale(dates[i]);
         })

         .attr("y", (d,i) =>{
          return height - d 
         })
          .classed("bar", true)
          .on("mouseover", function(d,i) {
              let coordinates = d3.mouse(this)
              const formYear = d3.timeFormat("%b %Y")
              d3.select(this)
             .classed("active", true)

                div.transition()
                .duration(200)	
                .style("opacity", .9)
                div.attr("data-date", datas[i][0])                 
                .html("Date " + "</br>" + formYear(dates[i]) + "</br>" + "$" + d3.select(this).attr("data-gdp"))	
                .style("left", event.clientX + "px")
                .style("top", (coordinates[1]) + "px")

            })
          .on("mouseout", function(d) {
            d3.select(this)
              .classed("active", false)                   
                div.transition()		
                .duration(100)		
                .style("opacity", 0);
        })
         .attr("width", width/275)
         .attr("height", (d) => {
           return d;
         })
         .attr("transform","translate(51,-30)")

      })
                                

              
            
!
999px

Console