Note that there are some explanatory texts on larger screens.

plurals
  1. POadd Y axis labels to D3 bar from json data name attribute
    primarykey
    data
    text
    <p>i was following the <a href="http://bost.ocks.org/mike/bar/" rel="nofollow">Let's make a Bar chart</a> tutorial and have run into an issue...in step three He rotates the bars to columns, and for the life of me I cannot figure out how to iterate over a json data set, and add Y-axis labels for each bars from the name attribute in the json data returned</p> <p>Here is the jsfiddle of my code <a href="http://jsfiddle.net/7K3tt" rel="nofollow">http://jsfiddle.net/7K3tt</a></p> <p>and the code samples below the json data loaded</p> <pre><code>[ { "name": "1-30 days", "value": "22" }, { "name": "31-60 days", "value": "14" }, { "name": "61-90 days", "value": "1" } ] </code></pre> <p>My D3 code</p> <pre><code>var width = 420, barHeight = 20; var x = d3.scale.linear() .range([0, width]); var chart = d3.select(".chart") .attr("width", width); d3.json("&lt;?=APP_PATH?&gt;/query", function(error, data) { x.domain([0, d3.max(data, function(d) { return d.value; })]); chart.attr("height", barHeight * data.length); var bar = chart.selectAll("g") .data(data) .enter().append("g") .attr("transform", function(d, i) { return "translate(0," + i * barHeight + ")"; }); bar.append("rect") .attr("width", function(d) { return x(d.value); }) .attr("height", barHeight - 1); bar.append("text") .attr("x", function(d) { return x(d.value) - 3; }) .attr("y", barHeight / 2) .attr("dy", ".35em") .text(function(d) { return d.value; }); }); function type(d) { d.value = +d.value; // coerce to number return d; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload