Skip to content

Instantly share code, notes, and snippets.

@kp666
Created June 5, 2018 09:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kp666/f5ab11f7220f4b53300b8649113716cc to your computer and use it in GitHub Desktop.
Save kp666/f5ab11f7220f4b53300b8649113716cc to your computer and use it in GitHub Desktop.
Basic scatter plot
license: mit
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>D3 Example</title>
<script src="//cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min.js"></script>
</head>
<style>
circle{fill: #40E0D0}
</style>
<body>
<script>
var svg = d3.select("body").append("svg")
.attr("width", 250)
.attr("height", 250);
function a_name (d){
// Bind data
var circles = svg.selectAll("circle").data(d);
// Enter
circles.enter().append("circle")
.attr("r", 15);
// Update
circles
.attr("cx", function (d){ return d.x; })
.attr("cy", function (d){ return d.y; });
// Exit
circles.exit().remove();
}
d3.csv("https://gist.githubusercontent.com/sandravizmad/7287d19eee4e427d988282dbcf81faaa/raw/1150864a4881223226559f6dae83155b0d3a0d05/test", function (d){a_name(d);});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment