Last active
July 24, 2017 22:56
-
-
Save denisemauldin/29e67cc465bd0eb884ee636b5f97ce08 to your computer and use it in GitHub Desktop.
Pie chart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<meta charset="utf-8"> | |
<html> | |
<head> | |
<script src="https://d3js.org/d3.v4.min.js"></script> | |
</head> | |
<body> | |
<div id="chart"></div> | |
<script> | |
dataset = [{"Company":"A", "value":131}, | |
{"Company":"B", "value":74}, | |
{"Company":"C", "value":97}]; | |
var width = 360; | |
var height = 360; | |
var radius = Math.min(width, height) / 2; | |
var color = d3.scaleOrdinal(d3.schemeCategory20b); | |
var svg = d3.select('#chart') | |
.append('svg') | |
.attr('width', width) | |
.attr('height', height) | |
.append('g') | |
.attr('transform', 'translate(' + (width / 2) + | |
',' + (height / 2) + ')'); | |
var arc = d3.arc() | |
.innerRadius(0) | |
.outerRadius(radius); | |
var pie = d3.pie() | |
.value(function(d) { return d.value; }) | |
.sort(null); | |
var path = svg.selectAll('path') | |
.data(pie(dataset)) | |
.enter() | |
.append('path') | |
.attr('d', arc) | |
.attr('fill', function(d) { | |
return color(d.data.Company); | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment