Skip to content

Instantly share code, notes, and snippets.

@allenyang79
Last active December 26, 2015 19:29
Show Gist options
  • Save allenyang79/7201261 to your computer and use it in GitHub Desktop.
Save allenyang79/7201261 to your computer and use it in GitHub Desktop.
d3 scale test 測試d3的scale基本用法
svg=d3.select('svg')
.attr('width','250px')
.attr('height','250px')
console.dir d3.select('svg')
data=[{x:35,y:10},{x:15,y:30}]
svg.selectAll('circle')
.data(data)
.enter()
.append('circle')
.attr('cx',(d)->return d.x)
.attr('cy',(d)->return d.y)
.attr('r',(d)->10)
#console.dir(data)
console.log "Hello"
d3.select("p").text("hello world this is p")
d3.select("body").append("p").text("Hihi append").style("color",'#900')
svg.append('line')
.attr('x1',0)
.attr('y1',0)
.attr('x2',100)
.attr('y2',100)
.attr('stroke','green')
.attr("stroke-width",10)
.attr('color','#f00')
data=[20,40,50,60,20,25,33,12,28,38,19]
xscale=d3.scale.linear()
.domain([0,50])
.range([0,250])
color=d3.scale.linear()
.domain([0,60])
.range(["red","blue"])
svg.selectAll('rect')
.data(data)
.enter()
.append('rect')
.attr('width',(d)->return xscale(d))
.attr('height',(d)->return 9)
.attr('fill',(d)->return color(d))
.attr('y',(d,i)->return i*10)
svg{
border:1px dashed #ccc;
}
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>JS Bin</title>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/d3/3.3.3/d3.min.js"></script>
</head>
<body>
<p></p>
<svg></svg>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment