Skip to content

Instantly share code, notes, and snippets.

@AndrewStaroscik
Last active November 11, 2016 17:30
Show Gist options
  • Save AndrewStaroscik/d6f8ac0c466e77b61adec89c3138ef05 to your computer and use it in GitHub Desktop.
Save AndrewStaroscik/d6f8ac0c466e77b61adec89c3138ef05 to your computer and use it in GitHub Desktop.
d3 oval text
license: gpl-3.0

Trouble shooting a problem with drawing circles.

Darker circle should be an oval. The lighter one should be a circle.

EDIT: The solution was to add an ellipse to the svg rather than a circle.

<!DOCTYPE html>
<meta charset="utf-8">
<svg width="960" height="200"></svg>
<script src="https://d3js.org/d3.v4.min.js"></script>
<script>
var svg = d3.select("svg"),
width = +svg.attr("width"),
height = +svg.attr("height");
svg.append('ellipse')
.attr('cx', 150)
.attr('cy', 100)
.attr('rx', 25)
.attr('ry', 50)
.style('fill', 'darkseagreen')
.style('stroke', '#232323');
svg.append('circle')
.attr('cx', 450)
.attr('cy', 100)
.attr('r', 50)
.style('fill', 'lightseagreen')
.style('stroke', '#232323');
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment