Built with blockbuilder.org
Last active
June 14, 2017 09:38
-
-
Save basilesimon/73384729de96f3fb7d8afc3b0130c6b9 to your computer and use it in GitHub Desktop.
Canvas concentric circles
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
license: mit |
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> | |
<head> | |
<meta charset="utf-8"> | |
<script src="https://d3js.org/d3.v4.min.js"></script> | |
<style> | |
body { background-color: #F5EFEB; margin:0;position:fixed;top:0;right:0;bottom:0;left:0; } | |
</style> | |
</head> | |
<body> | |
<script> | |
// Feel free to change or delete any of the code you see in this editor! | |
var canvas = d3.select("body").append("canvas") | |
.attr("width", 960) | |
.attr("height", 500); | |
var context = canvas.node().getContext('2d'); | |
var total = 100; | |
var turnout = 68; | |
var x = d3.scaleLinear().range([0,100]).domain([0,100]); | |
context.fillStyle = '#ddd' | |
context.beginPath(); | |
context.arc(100, 100, x(total), 0, 2 * Math.PI, true); | |
context.fill(); | |
context.closePath(); | |
context.fillStyle = '#383838'; | |
context.beginPath(); | |
context.arc(100, 100, x(turnout), 0, 2 * Math.PI, true); | |
context.fill(); | |
context.closePath(); | |
context.strokeStyle = '#383838'; | |
context.lineWidth = 5; | |
context.beginPath(); | |
context.moveTo(100, 100); | |
context.lineTo(250, 100); | |
context.stroke(); | |
context.font = '40pt Times'; | |
context.fillText('68,4%', 250, 100); | |
</script> | |
</script> | |
</body> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment