Pen Settings



CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs 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 its URL and the proper URL extension.

+ 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.


Auto Save

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 class="container"></div>



                html, body {
  height: 100%;

.container {
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;

.axis {
  color: #676767;




const colors = ["#F2C66B", "#D13D73"];

const margin = { top: 20, right: 20, bottom: 160, left: 45 }
const svgWidth = 420;
const svgHeight = 320;
const width = svgWidth - margin.left - margin.right
const height = svgHeight - - margin.bottom

const svg = d3
  .attr('width', svgWidth)
  .attr('height', svgHeight);

const graphArea = svg
  .attr('transform', `translate(${margin.left}, ${})`);

// Donloaded from
const dataURL = '';

(async () => {
  let data = await d3.csv(dataURL);

  const getX = d => d["Title"];
  const getY = d => +d["Num Votes"]; // convert to number from string

  // filter Top 10 data, and sort by num of votes
  data = data
    .slice(0, 20)
    .sort( (a, b) => -(getY(a) - getY(b)));

  You can use other options like
    - interpolateHcl
    - interpolateHsl
    - interpolateHcl
    - interpolateRgb
  const interpolated = d3.scaleLinear()
    .domain([0, data.length - 1])
  const x = d3.scaleBand()
    .range([0, width])

  const y = d3.scaleLinear()
    .range([height, 0])
      d3.min(data, getY),
      d3.max(data, getY)

  const xAxis = d3.axisBottom(x);
  const yAxis = d3.axisLeft(y).ticks(5);

  const ax = graphArea
    .attr('class', 'axis')
    .attr('transform', `translate(0, ${height})`)

    .attr('class', 'axis')

        .style("fill", (_, i) => interpolated(i))
        .attr("x", d => x(getX(d)))
        .attr("y", d => y(getY(d)))
        .attr("width", x.bandwidth())
        .attr("height", d => height - y(getY(d)));

  const halfBandwidth = x.bandwidth() / 2;
  const offset = x.step() * x.paddingInner();
    .style("text-anchor", "start")
    .style("font-size", "10px")
    .attr("transform", `rotate(35)`);