score:2
Accepted answer
Interesting idea.
You can get the rects
grouped with each tick's g
by:
svg.selectAll(".x>.tick")
.data(data)
.append("rect")
.attr("class", "bar")
.attr("x", function(d) {
return -x.rangeBand()/2; // set x to be half width, tick g will position it
})
.attr("width", x.rangeBand())
.attr("y", function(d) {
return -(height - y(d.frequency)); // set y to negative
})
.attr("height", function(d) {
return height - y(d.frequency);
});
You then have to rewrite the transition since calling .call(xAxis);
will recreate the tick g
and remove the bars.
transition.selectAll(".x>.tick")
.delay(delay)
.attr("transform", function(d) {
return "translate(" + x0(d.letter) + ",0)";
});
Putting this together.
Source: stackoverflow.com
Related Query
- How to sort bar charts synchronous with the ticks of x axis
- How can I create a basic bar chart with unique counts on the y axis and a category on the x axis?
- How to make bar chart with additional vertical lines below the x axis
- How to make axis label of stacked bar chart in the middle of ticks chart in D3?
- How can I get the D3.js axis ticks and positions as an array?
- D3 grouped bar chart: How to rotate the text of x axis ticks?
- Make simple bar chart using C3 with separate columns on the x axis
- d3.js bar chart sorting: can't figure out how to sort x-axis labels along with bars
- Need help lining up x axis ticks with bars in D3.js bar chart
- How to modify axis labels in d3 for a stacked bar chart when the axis labels are mapped as part of the scale's domain
- How do I set custom ticks along the Xaxis in D3? or name the bars in a bar chart?
- Limit number of Y axis ticks by keeping a top tick above the bar in d3
- How to line up x axis on stacked bar chart with a line overlay in d3.js
- How to remove the comma in D3 axis ticks and remove the last tick?
- Extending the axis bar height in d3 js charts
- How is the number of ticks on an axis defined?
- Add a space between the axis and text with NVD3 charts
- With d3.js, how can I use the same script to create 3 charts with 3 datasources?
- Issue with the color of bar charts d3.js
- How to align ticks with bars in horizontal bar chart / row chart
- How to get the axis ticks of Plotly's scatter plot to be shown in Latex using Python? --- [Python, Plotly, Latex Representation]
- How can I make a bar chart starting from the 0 point of the y axis and not from the bottom of the svg?
- Bar chart: how could I align the data with countries when sorting in D3 v5?
- d3js - Stacked Bar Chart in Horizontal Axis - How do I set x so the bars are seperated?
- How do I assign ticks to be equal to a different key value from the same object from the one on which the axis is based on in D3.js?
- d3 Plus bar chart how to force fixed max y axis range independent of the max data value
- While creating a bar graph using d3 how to associate the bar height with the numbers on the scale?
- How to setup D3.js axis labels to show rounded numbers with the $ sign?
- How do I manage groups for a grouped bar chart with a dropdown to update the chart in D3?
- How to plot stacked bar chart according to the custom Y axis in D3
More Query from same tag
- d3.js Error : Invalid value for <g> attribute transform="translate(NaN,5)"
- Cannot select the whole stack when selecting the second stack on mouseover
- D3 lineRadial - what is the math behind this?
- Updating only those SVG elements where the underlying bound data has been modified
- D3 arrow marker
- Conditionally render a text element if a certain property is present in the data
- What's the best way to properly transition the rectangles, back and forth, horizontally, and indefinitely in D3?
- Treemap with d3: the x, y, dx & dy are NaN
- How to properly rotate text labels in a D3 sunburst diagram
- How can I continuously update the range of the x axis in d3 graph?
- Change colour based on data set (d3)
- Adding a Background to certain part of a graphic with nvd3
- D3 Plus - Dynamically changing the position of data points in Scatter Plot
- Hide Circle in d3.js
- Transition chaining and cancellation
- D3.js Line chart not updating properly when applying the general update pattern
- D3 Arc Diagram: Tooltip on Circle Mouseover Not Displaying
- DC.js range/focus charts not behaving correctly
- Reference line for line graph
- How to update data using on.click events in D3
- Circle chart with repulsive circles
- Horizontal Stacked Bar Chart with Two Y Axis Issues
- How to match data points in D3.js to match x-axis?
- Timing issue on multi-line chart?
- D3 simple drop down menu on click
- d3 ordering column rule based on JSON response
- d3.js Tree - Paging of child nodes v3.5
- Get d3 v4 zoom and drag working together - simple example
- How to add d3 GWT wrapper to vaadin?
- Datamaps: how to show popup on mouseover AND customize the mouseover event listener