comparison numerics/templates/bar.d3.html @ 155:2a124febcd49

prepping for labels
author Jeff Hammel <k0scist@gmail.com>
date Tue, 12 May 2015 16:04:05 -0700
parents ce0e1e5efe77
children 69940819bc8a
comparison
equal deleted inserted replaced
154:134bdb520040 155:2a124febcd49
19 <body> 19 <body>
20 <h1>{{title}}</h1> 20 <h1>{{title}}</h1>
21 <svg class="svgchart"></svg> 21 <svg class="svgchart"></svg>
22 <script> 22 <script>
23 var data = {{data}}; 23 var data = {{data}};
24 var labels = {};
24 var width = 420, 25 var width = 420,
25 barHeight = 20; 26 barHeight = 20;
26 var x = d3.scale.linear() 27 var x = d3.scale.linear()
27 .domain([0, d3.max(data)]) 28 .domain([0, d3.max(data)])
28 .range([0, width]); 29 .range([0, width]);
38 .attr("height", barHeight - 1); 39 .attr("height", barHeight - 1);
39 bar.append("text") 40 bar.append("text")
40 .attr("x", function(d) { return x(d) - 3; }) 41 .attr("x", function(d) { return x(d) - 3; })
41 .attr("y", barHeight / 2) 42 .attr("y", barHeight / 2)
42 .attr("dy", ".35em") 43 .attr("dy", ".35em")
43 .text(function(d) { return d; }); 44 .text(function(d) {
45 var label = labels[String(d)];
46 if (label == undefined) {
47 return d;
48 } else {
49 return label + " : " + d;
50 }
51 });
44 </script> 52 </script>
45 </body> 53 </body>
46 </html> 54 </html>