score:7
Accepted answer
I have draw a d3 group barchart:
You can adjust the groupSpacing by change the code on line 56:
var groupSpacing = 6;
Technically i just achieve it by change the width of each rects' width:
var barsEnter = bars.enter().append('rect')
.attr('class', 'stm-d3-bar')
.attr('x', function(d,i,j) {
return (j * x1.rangeBand() );
})
.attr('y', function(d) { return y(d.y); })
.attr('height', function(d) { return height - y(d.y); })
.attr('width', x0.rangeBand() / barData.length - groupSpacing )
.attr('transform', function(d,i) {
return 'translate(' + x0(d.x) + ',0)';
})
.style("fill", function(d, i, j) {
return color(data[j].key);
});
Hope it helps you understand how you can achieve it in d3.
score:0
I minus the number of group spacing from the "width" attribute also. I found that the x-axis label looks a little off after I did that so I add the (group spacing / 2) to the "x" attribute. Here is the example of my code.
var groupSpacing = 15;
var rect = groups.selectAll("rect")
.data(function (d) { return d; })
.enter()
.append("rect")
.attr("x", function (d) { return x(d.x) + (groupSpacing / 2) ; })
.attr("y", function (d) { return y(d.y0 + d.y); })
.attr("height", function (d) { return y(d.y0) - y(d.y0 + d.y); })
.attr("width", x.rangeBand() - groupSpacing)
Source: stackoverflow.com
Related Query
- How to add space between bars in a grouped bar chart in a nvd3 grouped multibar chart?
- How to correctly centre text element on all bars of a nvd3 bar chart
- How can we add the space between bars for multiple groups of bars in c3js?
- D3 : How to add labels top of in each bar in grouped bar chart
- How to add text legends in bars of a bar chart in D3?
- Vega-lite bar chart space between bars
- How to draw multiple bars in a row in a bar chart with spaces in between with d3v5?
- How to reduce padding between bars in grouped bar chart?
- How to remove spaces between bars in grouped bar charts in d3
- How to reduce space b/w bars in group bar chart D3 v4
- How to add tool-tips in d3 js vertically grouped bar chart
- MultiBar chart with nvd3 / d3 only shows labels for every other tick on the x-axis. How can I get them all to show up?
- d3.js How to add lines to a bar chart
- d3.js bar chart sorting: can't figure out how to sort x-axis labels along with bars
- How to add a line on x-axis on a horizontal bar chart in d3
- Adding Error Bars to Grouped Bar Chart with D3.js
- D3.js : How to read data from JSON in Grouped Bar Chart
- How to make grouped stacked bar chart in d3js?
- How to create vertically grouped bar chart in d3.js using json data?
- nvd3 space between bars
- Add Zoom to a Grouped Bar Chart that uses a scaleBand
- How to reduce rect size in a grouped bar chart d3js v4
- Sorting the bars and getting the group data in a grouped bar chart
- How can I use D3.js "onClick" event with an nvd3 bar when zoomed in on chart data?
- d3.js bar chart - show/hide bars on legend click. how to filter correctly?
- How to get second bars to show on grouped bar chart?
- How to display second y-axis to right of grouped bar chart data in d3
- How to add live data to stacked bar chart
- How to add space between axis and line in D3 line chart?
- How to add non linear curve between any two points of area chart in d3.js
More Query from same tag
- Kernel density smoothing in d3.js
- Formatting nvd3 line chart axis
- Why is this SVG Path showing incorrect width and height on Firefox?
- d3 v4 js : attribute error
- Applying stroke-dasharray style to only part of a path
- How to wait on d3.json to finish?
- d3 js triangle in svg path
- d3 directed graph with varying stroke-widths
- dc-js line chart showing extra filled line at average change
- Trouble with NVD3 Graph showing x-axis in order of the data in array
- svg - corner not sharp as expected
- What do sub-transitions inherit?
- Filtering by Negation Crossfilter
- AngularJS: Unit Testing Directive w/ Promise returned from a Service
- D3: Separating data exit/remove/merge from drawing of elements
- D3: load hyperlink dynamically on click
- Unable to add text on link in d3 collapsible tree
- Unable to select <linearGradient> with D3.js in Chrome
- How to display text dynamically in svg
- Mouseover Effect D3.js
- D3.js TreeMap - Error: <rect> attribute width: Expected length, "NaN"
- D3.js zoom functionality in node-map
- d3 mouse argument with jquery
- d3-celestial library export to SVG
- D3 line generator only generating NaN values
- Inverting SVG image mask
- Small Box to display where we are hovering in force layout (D3.js)
- How to get coordinates of an svg element?
- dependent filtering with two jquery dropdowns
- move a slice of the pie chart using d3.js