Pen Settings

HTML

CSS

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

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

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.

HTML

              
                <script src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/94349/d3.v4.min.js"></script>

<div class="chart-container">
  <div class="p2g-chart" id="p2g-chart">
  </div>
</div>
              
            
!

CSS

              
                .chart-container {
  text-align: center;
  font-family: 'avenir next','Open Sans', sans-serif;
}

.axis path, .axis line {
    stroke: none;
    shape-rendering: crispEdges;
}

g.tick text {
    font-family: 'Avenir Next', 'Open Sans', sans-serif;
    font-size: .75rem;
    fill: gray;
}

text.value {
  font-size: 1.25rem;
}
              
            
!

JS

              
                var w = 960;
var h = 192;
var margin = { top: 0, left: 96, right: 0, bottom: 0 };
var svg = d3.select("#p2g-chart")
  .append("svg")
  .attr("viewBox", "0 0 " + (w + margin.left + margin.right) + " " + (h + margin.top + margin.bottom))
  .attr("preserveAspectRatio", "xMidYMid slice")
  .classed("svg-content", true)
  .attr("transform", "translate(0,0)");

var data = [
  {
    Item: "% to Shift Goal",
    Completed: "3",
    Confirmed: "5",
    Scheduled: "10",
    Projected: "3",
    Goal: "4",
    Total: "34"
  }
];

var xScale = d3.scaleLinear()
  .rangeRound([0, w - margin.left - margin.right])
  .domain([0, d3.max(data, function(d) {
                 return d.Total;
  })]);

var yScale = d3.scaleBand()
  .rangeRound([h - margin.top - margin.bottom, 0])
  .padding(0.5)
  .domain(
    data.map(function(d) {
      return d.Item;
    })
  );

var yAxis = d3.axisLeft(yScale);
svg.append("g")
  .attr("class", "axis")
  .attr("transform", "translate(" + margin.left + ", " + margin.top + ")")
  .call(yAxis);

var barStart = margin.left;
var tickMargin = margin.top+66;
var barCompleted = svg
  .append("g")
  .attr("transform", "translate(" + barStart + ", " + margin.top + ")")
  .classed("bars", true);
barCompleted.selectAll("rect")
  .data(data)
  .enter()
  .append("rect")
  .attr("width", function(d,i) {
           barStart+=xScale(d.Completed);
           return xScale(d.Completed);
  })
  .attr("height", yScale.bandwidth())
  .attr("y", function(d, i) {
    return yScale(d.Item);
  })
  .attr("fill", "rgba(37,207,63,.9)");
var tickCompleted = svg
  .append("g")
  .attr("transform", "translate(" + (barStart - 1) + "," + tickMargin + ")")
  .append("rect")
  .attr("width", ".1%")
  .attr("height", "100%")
  .attr("fill", "rgba(37,207,63,.9)");
var textCompleted = svg
  .append("g")
  .attr("transform", "translate(" + (barStart - 1) + "," + tickMargin + ")")
  .append("text")
  .attr("text-anchor","start")
  .attr("dy","62%")
  .attr("dx", ".5%")
  .text("Completed")
  .attr("class", "value")
  .attr("fill", "#444");
var textCompletedValue = svg
  .append("g")
  .attr("transform", "translate(" + (barStart - 1) + "," + tickMargin + ")")
  .append("text")
  .attr("text-anchor","start")
  .attr("dy","50%")
  .attr("dx", ".5%")
  .text("11")
  .attr("class", "value")
  .attr("fill", "#777");
var barConfirmed = svg
  .append("g")
  .attr("transform", "translate(" + barStart + ", " + margin.top + ")")
  .classed("bars", true);
barConfirmed.selectAll("rect")
  .data(data)
  .enter()
  .append("rect")
  .attr("width", function(d,i) {
           barStart+=xScale(d.Confirmed);
           return xScale(d.Confirmed);
  })
  .attr("height", yScale.bandwidth())
  .attr("y", function(d, i) {
    return yScale(d.Item);
  })
  .attr("fill", "rgba(37,207,63,.7)");
var tickConfirmed = svg
  .append("g")
  .attr("transform", "translate(" + (barStart - 1) + "," + tickMargin + ")")
  .append("rect")
  .attr("width", ".1%")
  .attr("height", "100%")
  .attr("fill", "rgba(37,207,63,.7)");
var textConfirmed = svg
  .append("g")
  .attr("transform", "translate(" + (barStart - 1) + "," + tickMargin + ")")
  .append("text")
  .attr("text-anchor","start")
  .attr("dy","62%")
  .attr("dx", ".5%")
  .text("Confirmed")
  .attr("class", "value")
  .attr("fill", "#444");
var textConfirmedValue = svg
  .append("g")
  .attr("transform", "translate(" + (barStart - 1) + "," + tickMargin + ")")
  .append("text")
  .attr("text-anchor","start")
  .attr("dy","50%")
  .attr("dx", ".5%")
  .text("8")
  .attr("class", "value")
  .attr("fill", "#777");
var barScheduled = svg
  .append("g")
  .attr("transform", "translate(" + barStart + ", " + margin.top + ")")
  .classed("bars", true);
barScheduled.selectAll("rect")
  .data(data)
  .enter()
  .append("rect")
  .attr("width", function(d,i) {
           barStart+=xScale(d.Scheduled);
           return xScale(d.Scheduled);
  })
  .attr("height", yScale.bandwidth())
  .attr("y", function(d, i) {
    return yScale(d.Item);
  })
  .attr("fill", "rgba(37,207,63,.5)");
var tickScheduled = svg
  .append("g")
  .attr("transform", "translate(" + ( barStart - 1 )+ "," + tickMargin + ")")
  .append("rect")
  .attr("width", ".1%")
  .attr("height", "100%")
  .attr("fill", "rgba(37,207,63,.5)");
var textScheduled = svg
  .append("g")
  .attr("transform", "translate(" + (barStart - 1) + "," + tickMargin + ")")
  .append("text")
  .attr("text-anchor","start")
  .attr("dy","62%")
  .attr("dx", ".5%")
  .text("Sched")
  .attr("class", "value")
  .attr("fill", "#444");
var textScheduledValue = svg
  .append("g")
  .attr("transform", "translate(" + (barStart - 1) + "," + tickMargin + ")")
  .append("text")
  .attr("text-anchor","start")
  .attr("dy","50%")
  .attr("dx", ".5%")
  .text("9")
  .attr("class", "value")
  .attr("fill", "#777");
var barProjected = svg
  .append("g")
  .attr("transform", "translate(" + barStart + ", " + margin.top + ")")
  .classed("bars", true);
barProjected.selectAll("rect")
  .data(data)
  .enter()
  .append("rect")
  .attr("width", function(d,i) {
           barStart+=xScale(d.Projected);
           return xScale(d.Projected);
  })
  .attr("height", yScale.bandwidth())
  .attr("y", function(d, i) {
    return yScale(d.Item);
  })
  .attr("fill", "rgba(225,237,242,.8)");
var tickProjected = svg
  .append("g")
  .attr("transform", "translate(" + (barStart - 1) + "," + tickMargin + ")")
  .append("rect")
  .attr("width", ".1%")
  .attr("height", "100%")
  .attr("fill", "rgba(225,237,242,.8)");
var textProjected = svg
  .append("g")
  .attr("transform", "translate(" + (barStart - 1) + "," + tickMargin + ")")
  .append("text")
  .attr("text-anchor","start")
  .attr("dy","62%")
  .attr("dx", ".5%")
  .text("Projected")
  .attr("class", "value")
  .attr("fill", "#444");
var textProjectedValue = svg
  .append("g")
  .attr("transform", "translate(" + (barStart - 1) + "," + tickMargin + ")")
  .append("text")
  .attr("text-anchor","start")
  .attr("dy","50%")
  .attr("dx", ".5%")
  .text("31")
  .attr("class", "value")
  .attr("fill", "#777");
var textProjectedInset = svg
  .append("g")
  .attr("transform", "translate(" + (barStart - 1) + "," + margin.top + ")")
  .append("text")
  .attr("text-anchor","start")
  .attr("dy","54.5%")
  .attr("dx",".5%")
  .text("91%")
  .attr("class", "value")
  .attr("fill", "#666");
var barGoal = svg
  .append("g")
  .attr("transform", "translate(" + barStart + ", " + margin.top + ")")
  .classed("bars", true);
barGoal.selectAll("rect")
  .data(data)
  .enter()
  .append("rect")
  .attr("width", function(d,i) {
           barStart+=xScale(d.Goal);
           return xScale(d.Goal);
  })
  .attr("height", yScale.bandwidth())
  .attr("y", function(d, i) {
    return yScale(d.Item);
  })
  .attr("fill", "rgba(225,237,242,.4)");
var tickGoal = svg
  .append("g")
  .attr("transform", "translate(" + (barStart - 1) + "," + tickMargin + ")")
  .append("rect")
  .attr("width", ".1%")
  .attr("height", "100%")
  .attr("fill", "rgba(225,237,242,.4)");
var textGoal = svg
  .append("g")
  .attr("transform", "translate(" + (barStart - 1) + "," + tickMargin + ")")
  .append("text")
  .attr("text-anchor","start")
  .attr("dy","62%")
  .attr("dx", ".5%")
  .text("Goal")
  .attr("class", "value")
  .attr("fill", "#444");
var textGoalValue = svg
  .append("g")
  .attr("transform", "translate(" + (barStart - 1) + "," + tickMargin + ")")
  .append("text")
  .attr("text-anchor","start")
  .attr("dy","50%")
  .attr("dx", ".5%")
  .text("34")
  .attr("class", "value")
  .attr("fill", "#777");
              
            
!
999px

Console