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. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ add another resource


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


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.


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.


                <div id="chart"></div>


                svg {
  background-color: #F5E1E1;
body {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
#tooltip {
  display: flex;
  align-items: center;
  justify-content: center;
  position: absolute;
  width: 150px;
  overflow: auto;
  padding: 10px;
  font: 12px;
  background-color: white;
  box-shadow: 1px 1px 10px;
  border-radius: 20px;
  pointer-events: none;



                //Retrieve data for chart
d3.json('', function(unmappedDataset) {
  //Filter data required and organise it by seperating it
  const mappedDataset = => ({
                                    year: item["Year"],
                                    time: item["Seconds"]  
  const yearsArray = => item["Year"]);
  const stringTimesArr = => item["Time"]);
  //Convert yearsArray from number format to date format
  const convYearsArray = => new Date(item, 0, 0, 0, 0, 0, 0));
  //Change stringTimesArr array from string to date format
  unmappedDataset.forEach(function (d) {
    var parsedTime = d.Time.split(':');
    d.Time = new Date(1970, 0, 1, 0, parsedTime[0], parsedTime[1]);
  const dateTimeArr = => item["Time"]);
  //Set svg (where graph will be) dimensions
  const w = 1000;
  const h = 500;
  const padding = 60;
  //Create svg area (where graph will be)
  const svg ="#chart")
  .attr("width", w)
  .attr("height", h);
  //Create scales to make graph fit page
  const xScale = d3.scaleTime()
  .domain([new Date(1993,0,0,0,0,0,0), new Date(2016,0,0,0,0,0,0)])
  .range([padding+10, w - padding]);

  const yScale = d3.scaleLinear()
  .domain([d3.min(dateTimeArr), d3.max(dateTimeArr)])
  .range([h - padding, padding]);

  //Create and place dots
    .attr('data-xvalue', (d, i) => yearsArray[i])
    .attr('data-yvalue', (d, i) => dateTimeArr[i])
    .attr("cx", (d, i) => xScale(convYearsArray[i]))
    .attr("cy", (d, i) => yScale(dateTimeArr[i]))
    .attr("r", 5)
    .attr("fill", (item) => {if(item["Doping"] == ""){return "orange"}else{return "navy"}})
    .attr("class", "dot")
    .on("mouseover", handleMouseOver)
    .on("mouseout", handleMouseOut)
  //Create chart title 
    .attr("x", w / 2 )
    .attr("y", padding/2)
    .style("text-anchor", "middle")
    .text("Doping in Professional Bicycle Racing - 35 Fastest times up Alpe d'Huez")

  //Create X axis 
  const xAxis = d3.axisBottom(xScale);

    .attr("transform", "translate(0," + (h - padding) + ")")
  //Create Y axis 
  const yAxis = d3.axisLeft(yScale).tickFormat(d3.timeFormat('%M:%S'));

    .attr("transform", "translate(" + (padding+10) + ",0)")

  //X axis title
    .attr("class", "x label")
    .attr("text-anchor", "end")
    .attr("x", w/2)
    .attr("y", h - padding*0.25)
  //Y axis title
    .attr("class", "y label")
    .attr("text-anchor", "end")
    .attr("y", 6)
    .attr("x", -h/4)
    .attr("dy", ".75em")
    .attr("transform", "rotate(-90)")
    .text("Time up Alpe d'Huez (seconds)");
  //Create tooltip   
  const tooltip ='#chart')
                    .attr('id', 'tooltip')
                    .style('opacity', 0);
  // Create Event Handlers for mouse
  function handleMouseOver(d, i) {  
      .style("opacity", 0.9)
      .html(yearsArray[i] + '<br>' + stringTimesArr[i] + '<br>' + unmappedDataset[i]["Name"] + '<br>' + unmappedDataset[i]["Nationality"] + '<br>' + unmappedDataset[i]["Doping"])
      .style('left', d3.event.pageX + 10 + 'px')
      .style('top', d3.event.pageY - 28 + 'px');
  function handleMouseOut(d, i) {"opacity", 0);
      .attr("fill", (item) => {if(item["Doping"] == ""){return "orange"}else{return "navy"}})
  // Create legend
  // Handmade legend
  const legend = svg.append("g")
                    .attr("id", "legend")
        .attr("width", 20)
        .attr("height", 20)
        .style("fill", "orange")
        .attr("width", 20)
        .attr("height", 20)
        .style("fill", "blue")
        .attr("x", w*0.69)
        .attr("y", h*0.77)
        .text("No doping allegations")
        .style("font-size", "15px")
        .attr("x", w*0.69)
        .attr("y", h*0.82)
        .text("Riders with doping allegations")
        .style("font-size", "15px")