comparison numerics/templates/bar.d3.html @ 156:69940819bc8a

allow for labels in an assenine way
author Jeff Hammel <k0scist@gmail.com>
date Tue, 12 May 2015 16:25:37 -0700
parents 2a124febcd49
children
comparison
equal deleted inserted replaced
155:2a124febcd49 156:69940819bc8a
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 labels = {{labels}};
25 var width = 420, 25 var ctr = 0;
26 var width = 960,
26 barHeight = 20; 27 barHeight = 20;
27 var x = d3.scale.linear() 28 var x = d3.scale.linear()
28 .domain([0, d3.max(data)]) 29 .domain([0, d3.max(data)])
29 .range([0, width]); 30 .range([0, width]);
30 var chart = d3.select(".svgchart") 31 var chart = d3.select(".svgchart")
40 bar.append("text") 41 bar.append("text")
41 .attr("x", function(d) { return x(d) - 3; }) 42 .attr("x", function(d) { return x(d) - 3; })
42 .attr("y", barHeight / 2) 43 .attr("y", barHeight / 2)
43 .attr("dy", ".35em") 44 .attr("dy", ".35em")
44 .text(function(d) { 45 .text(function(d) {
45 var label = labels[String(d)]; 46 return labels[ctr++];
46 if (label == undefined) {
47 return d;
48 } else {
49 return label + " : " + d;
50 }
51 }); 47 });
52 </script> 48 </script>
53 </body> 49 </body>
54 </html> 50 </html>