score:3
Here is what I could do:
The basis is to have two values per item. To simplify things we can say that all values have to be positive, the first one will be displayed on the right, the second one on the left.
From the example you provided, we will just plot the second value we add:
data = [
{name: "A",value: 1,value2: 2},
...
]
We will also fix the domain (you can write a function to do it nicely afterwards):
x.domain([-10,10])
Finally, we will draw the second bars (on the left):
svg.selectAll(".bar2")
.data(data)
.enter().append("rect")
.attr("class", "bar2")
.attr("x", function (d) {
return x(Math.min(0, -d.value2));
})
.attr("y", function (d) {
return y(d.name);
})
.attr("width", function (d) {
return Math.abs(x(-d.value2) - x(0));
})
.attr("height", y.rangeBand());
This code is just copy paste from the example where I replaced d.value
by -d.value1
and .bar
by .bar2
for the class.
You will also have to modify the x-axis format for having "75, 50, 25, 0, 25, 50, 75".
jsFiddle: http://jsfiddle.net/chrisJamesC/vgZ6E/
Source: stackoverflow.com
Related Query
- d3.js bar chart with pos & neg bars (win/loss) for each record
- d3.js bar chart sorting: can't figure out how to sort x-axis labels along with bars
- Adding Error Bars to Grouped Bar Chart with D3.js
- Need help lining up x axis ticks with bars in D3.js bar chart
- Sorting the bars in a bar chart with dc.js
- d3 show labels only for ticks with data in a bar chart
- D3 - How to loop through an object with keys for a bar chart
- Preview d3 bar chart such that it sorted by values for each x value
- Get unique max value for each y-axis in a bar chart
- Transitioning a bar chart with negative values for the width
- Create a bar chart with local storage data (drawing the bars doesn't work)
- How to create a multi-series line chart with series for each unique item in 1st column?
- Creating a radial chart with a different color for each axis label
- How to draw multiple bars in a row in a bar chart with spaces in between with d3v5?
- D3 Bar Chart with Variable X and Y(variable width and height for bars)
- draw horizontal lines for bars in nvd3 multi bar chart
- Changing the colors of each of the Stacked Bar chart with different Color in D3
- DC.js bar chart x-axis labels not aligned with bars
- nvd3.js - display specific color for each bar in multibar vertical chart depending on range of value
- Showing a bar chart with expected value and current value for a series
- d3 bar chart align bars on ticks for differing number of elements
- How to align ticks with bars in horizontal bar chart / row chart
- Is it possible to select multiple bars on bar chart in d3.js with mouse
- If condition never met and hence my bars in a simple bar chart are always blue, while I want them to be red for values below a certain number
- stacked bar chart with overlapping bars C3js
- D3 fill for a horizontal stacked bar chart in Angular with typeScript: .attr("fill", ..) gets error "No overload matches this call" in VSC
- How do I manage groups for a grouped bar chart with a dropdown to update the chart in D3?
- Trying to get circles on map to transition into bars in bar chart with D3
- Differentiating between bars in tooltip for stacked bar chart
- Data model for creating a radial bar chart with d3js
More Query from same tag
- Insert text in Rectangle - D3.js
- How to add a list of node's name with tooltip in sankey
- D3.Js Clicking function with a text box or alert box
- D3 Converting a Stacked Area Graph from tsv to csv using Mike Bostock's example
- D3 dynamic json key names
- Remove Attributes/Points D3.js JQuery
- Day hour Heatmap - Colors not showing
- easily get text appended to a node on d3 graph
- D3 Does not render or paint DOM element
- Create tree hierarchy from csv in d3.js
- Parsing Error While using D3 and Crossfilter with CSV
- Adding time to d3 charts
- D3 v4 - Detect click coordinates in zoomed area
- js var does not get value of document.getElementById( ).value
- How to display text on donut chart for mouseover event
- Creating an area chart: path with NaN
- d3 tooltip position issue in line chart using javascript
- How D3 key function in data binding works
- dynamically angle linear gradient of svg
- d3 lines and circles data
- returning the result of anonymous callback in d3.json
- Combine multiple events in D3
- D3js: blocks with text inside & hover to show more text
- d3.js Gantt chart
- D3 - reordering elements based on their data
- D3js - Force directed graph - advanced highlighting of neigbour nodes and links, is it possible?
- put hellip (...) to a text that is inside of bar in d3.js
- D3 arc gradient
- Datamaps not displaying in my browser
- How can I skip an element of an array when I perform a .data (data) in d3.js