D3.js column chart inversing when adding text -
i trying create basic column chart using divs example in allignedleft , 1 mike has posted. chart works except when add text, inverses.
<!doctype html> <head> <style type="text/css"> div.abc { display: inline-block; width: 20px; height: 75px; background-color: teal; margin-right: 2px; } </style> </head> <body> <script type="text/javascript" src="http://d3js.org/d3.v2.js?2.8.1"></script> <script> var dataset = [16,13,8,2,1,10,0,5,24,15,2,6,12]; d3.select("body").selectall("div") .data(dataset) .enter() .append("div") .attr("class", "abc") .style("height", function(d) { var barheight = d * 5; return barheight + "px"; }) .style("margin-top",function(d) { var barheight = d * 5; return 500 - barheight; }) .style("text-align","center") .style("color","black") .text(function (d) { return d; }); </script> </body> </html> thanks
sriram
the problem vertical alignment of text in divs. if add
vertical-align: bottom; to css, should work again. note of divs small text. in these cases, labels won't aligned rest. recommend create separate divs labels , place them accordingly.
Comments
Post a Comment