Designed by Stephen Few, a bullet chart “provides a rich display of data in a small space.” A variation on a bar chart, bullet charts compare a given quantitative measure (such as profit or revenue) against qualitative ranges (e.g., poor, satisfactory, good) and related markers (e.g., the same measure a year ago). Layout inspired by Stephen Few. Implementation by Mike Bostock based on work by Clint Ivy, Jamie Love of N-Squared Software and Jason Davies. The "update" button randomizes the values slightly to demonstrate transitions.
forked from wboykinm's block: Bullet Chart
forked from rakuehr's block: Bullet Chart
xxxxxxxxxx
<!-- <meta charset="utf-8"> -->
<style>
body {
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
margin: auto;
padding-top: 40px;
position: relative;
width: 960px;
}
.bullet { font: 15px sans-serif; }
/* .bullet .tick line { stroke: #666; stroke-width: .5px; } */
.bullet .range.s0 { fill: #00a144; } /*Green Range*/
.bullet .range.s1 { fill: #edac1a; } /* Yellow Range */
.bullet .range.s2 { fill: #d91b1b; } /*Red Range */
.bullet .measure.s0 { fill: #8379b8; } /* Actual Value (Purple Range) */
.bullet .measure1{ fill: #000000;font-weight: bold; } /*Measure value at the end of the purple range ie 99% */
.bullet .title { font-size: 14px; font-weight: bold; } /* Title: Autofills as black add fill: #hexnum; to change the color of the title */
.bullet .subtitle { fill: #999; } /* Subtitle (Currently grey) */
</style>
<script src="https://d3js.org/d3.v3.min.js"></script>
<script src="bullet.js"></script>
<script>
var margin = {top: 5, right: 40, bottom: 30, left: 80}, //Define the size of the area we are working in
width = 315 - margin.left - margin.right, //450 to get side/side
height = 70 - margin.top - margin.bottom;
var chart = d3.bullet() //Defining the chart size
.width(width)
.height(height);
d3.json("bullets.json", function(data) { //This function draws/creats the chart
var svg = d3.select("body").selectAll("svg")
.data(data)
.enter().append("svg")
.attr("class", "bullet")
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.top + margin.bottom)
.append("g")
.attr("transform", "translate(" + margin.left + "," + margin.top + ")")
.call(chart);
var title = svg.append("g")
.style("text-anchor", "end")
.attr("transform", "translate(-6," + height / 2 + ")"); //Determines where the title and subtitle are located to the left of the graph
title.append("text")
.attr("class", "title")
.text(function(d) { return d.title; }); //Adds the title
title.append("text")
.attr("class", "subtitle")
.attr("dy", "1em")
.text(function(d) { return d.subtitle; }); //Adds the subtitle below the title
});
</script>
Modified http://d3js.org/d3.v3.min.js to a secure url
https://d3js.org/d3.v3.min.js