css Audio - Active file-generic CSS - Active Generic - Active HTML - Active JS - Active SVG - Active Text - Active file-generic Video - Active header Love html icon-new-collection icon-person icon-team numbered-list123 pop-out spinner split-screen star tv

Pen Settings

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. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation


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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

                <title id="title">graph</title>


<script src="https://cdn.freecodecamp.org/testable-projects-fcc/v1/bundle.js"></script>
              rect {
    fill-opacity: .6;
    background-color: black;

  .bar:hover {
    fill: brown;
  div.tooltip {	
    position: absolute;			
    text-align: center;			
    width: 80px;					
    height: 40px;					
    padding: 2px;				
    font: 12px sans-serif;		
    background: lightsteelblue;	
    border: 0px;		
    border-radius: 8px;			
    pointer-events: none;	
    line-height: 180%	;
    color: black;
    box-shadow: 0px 0px 25px 5px rgba(241, 239, 239, 0.75);
              var dataUrl = "https://raw.githubusercontent.com/freeCodeCamp/ProjectReferenceData/master/GDP-data.json";
var xhttp = new XMLHttpRequest();
var data = [];
var dataYearsArr = [];
var dataValuesArr = [];
var parseDate = d3.timeParse("%Y-%m-%d");
var formatDatevi = d3.timeFormat("%d.%m.%Y");
var formatDate = d3.timeFormat("%Y-%m-%d");
xhttp.onreadystatechange = function () {
    if (this.readyState == 4 && this.status == 200) {
        var json = JSON.parse(this.responseText);

        json.data.map((x) => data.push(x) && dataYearsArr.push(parseDate(x[0])) &&

        data.forEach(function(d) {
            d.datevi = formatDatevi (parseDate(d[0]));
            d.date = formatDate (parseDate(d[0]));
            d.value = +d[1];
        var padding = 50;
        var width = window.innerWidth- padding;
        var windowheigth = window.innerHeight;

        var height = windowheigth ;
        var margintop = 30;

        const svg = d3.select("body")
            .append("svg").attr("width", width)
            .attr("height", height)
            .style("border", "1px dotted black");

        var scaley = d3.scaleLinear()
            .domain([0, d3.max(dataValuesArr)])
            .range([height - padding,0]);
        var axisy = d3.axisLeft(scaley).ticks(40);


            .attr("transform", "translate(" + padding + "," + 0 + ")")
            .attr("id", "y-axis")
            .attr("class", "tick")

        var scalex = d3.scaleTime()
            .domain([(dataYearsArr[0]), (dataYearsArr[dataYearsArr.length - 1])])
            .range([padding, width - 0]);

        var axisx = d3.axisBottom(scalex);


            .attr("id", "x-axis")
            .attr("class", "tick")
            .attr("transform", "translate(0," + (height - padding) + ")")

        var factorw =( (width - padding) / data.length);

        var factorh =(height -padding) / (d3.max(dataValuesArr));
        var div = d3.select("body").append("div")
            .attr("class", "tooltip")
            .attr("id", "tooltip")
            .style("opacity", 0);

            .attr("x", (d, i) => scalex(parseDate(d[0])) )
            .attr("width", (factorw))
            .attr("y", (d, i) => scaley(d[1])  )
            .attr("height", (d, i) => factorh * d[1])
            .attr("fill", "navy")
            .attr("class", "bar")
            .attr("data-date", (d, i) => d[0])
            .attr("data-gdp", (d) =>

            .on("mouseover", function (d) {
                    .style("opacity", 0.9);  
                div.html((d.datevi) + "<br/>" + d.value)             
                    .style("left", (d3.event.pageX) + "px")
                    .style("top", (d3.event.pageY - 28) + "px");
            }).on("mouseout", function (d) {
                    .style("opacity", 0);

        //Append group and insert axis

xhttp.open("GET", dataUrl, true);
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................