You need to change a lot of things in your code.
populationin the array
- scales are used to convert values to proportional pixel values
heightis the vertical size of an element. you should use
widthis the horizontal size of an element. you should use
yis the vertical position of an element. you should use
xis the vertical position of an element. you should use
selectAll("rect")on a new appended
svgelement not the same
gelement that has the axises on it
fillattribute so that your rects have color
You have the population field labelled
value but you're calling
population through out the code to use it. So replace value with population in your data objects.
Next you need to change the way you're setting up the rects. use selectAll on the
svg element directly or append another
g to the
svg element and add the rects on that element. Right now your code attempts to add the rects to the same
g element as the x axis.
Make sure you are setting the attributes of the rects correctly. Height is the size in pixels of the rect element not the position.
y is the position of the rects vertically from the top downwards. this means the
height attribute should use
width should use
xScale(d.population) because they are the width and length of the rectangles, or
y are the coordinate positions of the element from the top left corner of the
svg element. Use them to determine the starting position of the top left pixel of your rects. You should have
- d3js: Unable to place horizontally bars within the axis
- d3js - Stacked Bar Chart in Horizontal Axis - How do I set x so the bars are seperated?
- d3js display arrow at the end of each axis
- Different tick sizes on the Y axis of a D3js line graph
- Access the text within SVG object using d3js
- d3js x axis dates display month at the end not in the front
- Unable to get drop-shadow on the bars
- How to place the bars of a bar chart in the right positions of the xAxis using d3.js?
- A few bars in the wrong place in a bar graph after sorting in ascending order
- D3js scale chart have x axis in the middle
- d3js not having the same behaviour within and outside a function
- D3js Ordinal Axis does not show all the ticks
- Using d3js, how do I use the tree layout to visually place child nodes within their parent?
- Why is the color of the bars not filling and staying white? d3js
- 404 error - unable to find JSON file when making a map but it looks like it's in the right place
- Why the axis I generated using d3js is significantly different from the example even though the code are similar?
- how to fill the area between the bars in the given example d3js
- d3js using an attribute that is updated within the same callback
- d3.js: Align text labels between ticks on the axis
- How can I get the D3.js axis ticks and positions as an array?
- D3: Is it possible to zoom+pan one axis and only pan the other?
- D3js how to append 2 children at the same level in .enter context
- D3js within Java application
- D3js v4: scaleOrdinal does not have the rangePoints()
- D3 grouped bar chart: How to rotate the text of x axis ticks?
- how to set the domain and scale on an axis on a nvd3.js multiBarChart
- nvd3.js : unable to bind onClick event with the data points in the svg
- Make simple bar chart using C3 with separate columns on the x axis
- How to change line color in d3js according to axis value?
- How to display the value for the final tick on axis in D3?
More Query from same tag
- How to show hh:mm:ss format at y-axis with c3?
- D3 graph with slider need too change color of outside nodes
- n3 line chart x axis label
- Add brush on top of d3 barchart
- d3 - get scale of x an y for label
- d3js - .exit().remove() doesn't remove all data
- D3 - loading data with no header
- json values in variable for D3 chart throwing error.While the static json files works fine
- d3 - Graph Network Node Link Spacing
- D3.js horizontal histogram
- D3 - Unnecessary values in X Axis
- d3js diagonal paths in tree layout don't look right
- csv implementation with cal-heatmap jquery
- Adding text to rectangle elements using D3 / SVG
- D3.JS Browser Support
- How do you uses nested elements in a force directed D3 graph?
- Unable to understand d3js zoom functionality
- Tooltip for D3 Heatmap canvas
- d3 drag jumping to other position when clicked - origin?
- d3.format thousand separator on variables?
- Mapping an arc in D3 using d3.geo.path()
- D3.js fixed width tree with limited indentation
- Getting the max values from JSON in D3
- D3 - how do I remove comma separator from my xAxis?
- D3 example from Observable on my wordpress site
- how to make a radial line segment using D3.js
- Understanding enter() and exit()
- Transitioning circles, one by one
- Link in D3 bar chart
- Redrawing SVG on resize