Skip to content

Instantly share code, notes, and snippets.

@devgru
Last active August 29, 2015 13:59
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save devgru/10544108 to your computer and use it in GitHub Desktop.
Save devgru/10544108 to your computer and use it in GitHub Desktop.
<html>
<body>
<script type='text/javascript' src='http://d3js.org/d3.v3.min.js'></script>
<script>
array = [
{ 'a': 1, 'b': 2 },
{ 'a': 42, 'b': 7 },
{ 'a': 15, 'b': 3 },
{ 'a': 32, 'b': 8 },
{ 'a': 26, 'b': 15 },
{ 'a': 18, 'b': 5 }
]
margin = 10
y = d3.scale.linear()
.domain(d3.extent(array, function (v) {
return v.b
}))
.range([100 + margin, margin])
x = d3.scale.linear()
.domain(d3.extent(array, function (v) {
return v.a
}))
.range([margin, 100 + margin])
body = d3.select('body')
svg = body.append('svg')
circle = svg
.selectAll('circle')
.data(array)
circle.enter()
.append('circle')
.attr('r', 10)
.attr('fill', 'red')
.attr('cx', function (data, index) {
return x(data.a)
})
.attr('cy', function (d, i) {
return y(d.b)
})
</script>
<style>
svg {
width: 100%;
height: 200px;
}
</style>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment