score:8
Accepted answer
Currently isn't possible. That option is available only in the discrete bar chart.
From the maintainer:
We don't have this ability. Stacked/Grouped charts also have complex animations making this a tricky thing to solve. We use tooltips instead.
Source https://github.com/novus/nvd3/issues/150
If you want to do this you need to make your own implementation using d3. There is a good example here http://plnkr.co/edit/BNpAlFalKz0zkkSszHh1?p=preview. It's using the angular wrapper but it's a good starting point.
var app = angular.module('app', ['nvd3ChartDirectives']);
app.controller('chartCtrl', function($scope, $timeout) {
var ANIMATION_TIME = 1500,
countSeriesDisplayed = 2,
promise,
labels = ["label1", "label2", "label3", "label4", "label5"];
$scope.isStacked = false;
// Example data
$scope.chartData = [{
"key": "Series 1",
"values": [
[0, 10],
[1, 20],
[2, 30],
[3, 40],
[4, 50]
]
}, {
"key": "Series 2",
"values": [
[0, 10],
[1, 40],
[2, 60],
[3, 20],
[4, 40]
]
}];
/* To add labels, images, or other nodes on the created SVG, we need to wait
* for the chart to be rendered with a callback.
* Once the chart is rendered, a timeout is set to wait for the animation to
* finish.
*
* Then, we need to find the position of the labels and set it with the
* transform attribute in SVG.
* To do so, we have to get the width and height of each bar/group of bar
* which changes if stacked or not
*
*/
// Callback called when the chartData is assigned
$scope.initLabels = function() {
return function(graph) {
promise = $timeout(function() {
var svg = d3.select("svg"),
lastRects, rectWidth,
heightForXvalue = []; // Used for grouped mode
// We get one positive rect of each serie from the svg (here the last serie)
lastRects = svg.selectAll("g.nv-group").filter(
function(d, i) {
return i == countSeriesDisplayed - 1;
}).selectAll("rect.positive");
if ($scope.isStacked) {
// If stacked, we get the width of one rect
rectWidth = lastRects.filter(
function(d, i) {
return i == countSeriesDisplayed - 1;
}).attr("width");
} else {
// If grouped, we need to get the greatest height of each bar
var nvGroups = svg.selectAll("g.nv-group").selectAll("rect.positive");
nvGroups.each(
function(d, i) {
// Get the Min height space for each group (Max height for each group)
var rectHeight = parseFloat(d3.select(this).attr("y"));
if (angular.isUndefined(heightForXvalue[i])) {
heightForXvalue[i] = rectHeight;
} else {
if (rectHeight < heightForXvalue[i]) {
heightForXvalue[i] = rectHeight;
}
}
}
);
// We get the width of one rect multiplied by the number of series displayed
rectWidth = lastRects.filter(
function(d, i) {
return i == countSeriesDisplayed - 1;
}).attr("width") * countSeriesDisplayed;
}
// We choose a width equals to 70% of the group width
var labelWidth = rectWidth * 70 / 100;
var groupLabels = svg.select("g.nv-barsWrap").append("g");
lastRects.each(
function(d, index) {
var transformAttr = d3.select(this).attr("transform");
var yPos = parseFloat(d3.select(this).attr("y"));
groupLabels.append("text")
.attr("x", (rectWidth / 2) - (labelWidth /2)) // We center the label
// We add a padding of 5 above the highest rect
.attr("y", (angular.isUndefined(heightForXvalue[index]) ? yPos : heightForXvalue[index]) - 5)
// We set the text
.text(labels[index])
.attr("transform", transformAttr)
.attr("class", "bar-chart-label");
});
}, ANIMATION_TIME);
}
};
// Tooltips
$scope.toolTipContentFunction = function () {
return function (key, x, y, e, graph) {
return labels[x];
}
};
$scope.$on('$destroy', function () {
// Cancel timeout if still active
$timeout.cancel(promise);
});
});
UPDATE:
I've created a gist that could help you to implement this by yourself.
Source: stackoverflow.com
Related Query
- How to display values in Stacked Multi-bar chart - nvd3 Graphs
- how to display bar values in horizontal stacked bar chart
- How to display values on top of nvd3 multi par graph?
- D3 bar chart - how to display positive/negative values together?
- How to show values stacked bar chart utilizing dc.js and d3.js?
- How do I set the X values for a singled stacked horizontal bar chart using d3.js?
- How to display the total value of a stacked bar chart in d3js
- How to display total count on top of the stacked bar chart
- How to display sum of value in stacked bar chart
- Nvd3: How prevent to display chart between -1 and 1 if have all y values 0?
- d3.js - group 2 data values in a stacked bar chart
- How to force nvd3 to display the equal number of ticks as that of the values plotted on the graph-nvd3
- How to add space between bars in a grouped bar chart in a nvd3 grouped multibar chart?
- d3.js stacked bar chart with positive and negative values
- nvd3 stacked area chart looks glitchy how to fix?
- 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 to correctly centre text element on all bars of a nvd3 bar chart
- NVD3 Stacked Bar Chart Plus Line Overlapped
- How to make grouped stacked bar chart in d3js?
- d3.js create stacked bar chart from values in object
- d3/dc.js - How to create a stacked bar chart while telling crossfilter to treat elements in an array as separate records?
- How to line up x axis on stacked bar chart with a line overlay in d3.js
- How to create a stacked bar chart using dc.js?
- how to create a stacked bar chart with images in d3
- how to use d3 .ticks to show original y-axis values in bar chart
- D3 v6: How to zoom stacked bar by selected segment to stretch only selected segment and shrink rest segments (and keep initial chart width)?
- d3.js stacked bar chart sort / change order of individual values within a stack
- How to display negative values in a d3 bar chart?
- How can I use D3.js "onClick" event with an nvd3 bar when zoomed in on chart data?
- How to display second y-axis to right of grouped bar chart data in d3
More Query from same tag
- Item tooltips after filtering source data
- D3 change SVG dimensions on resize window
- Transition not working
- Creating Tool Tips Correctly Based on Individual Sums
- use any curve to connect two certain points with certain link length using javascript of its library such as d3
- Zooming example in dimple.js?
- Line Plus Bar Chart - Is there any way to pass date as string without formatting?
- How to register multiple external listeners to the same selection in d3?
- d3 all branches on top of each other vertical dendogram. r2d3 shiny
- Custom D3 `tickValue` on x axis -- horizontal bar chart
- Animating a line's movement to match speed of linear path
- d3.js : d3.min.js:1 Error: <path> attribute d: Expected number, "MNaN,NaNLNaN,NaN"
- Center align legend text and circle
- How to place marker head in the middle of the links
- flip action in d3 js
- D3 Force Layout with text Label And Icon
- Assigning heights dynamically, based on arithmetic series
- d3 stuck histogram to axis
- what does the equation within d3.nest().entries() do?
- Javascript/JQuery for Datatables
- I am learning D3.js but I don't get the same console output as tutorials
- What is "defensive reference" in javascript?
- force directed graph different cluster for different groups
- d3.js, is it possible to append hyperlinks to GeoJSON file?
- How to get data on x-axis and number of times occured on y-axis using crossfilter JS?
- Format the legend of my donut chart
- Draw layered arc in D3
- d3 version 4 zoom behaviour on g element
- Bivariate Line Graph using Nested element data
- Adding labels to D3 generated circles