问题
I'd like to set custom tick number and labels for my discrete chart done in nvd3. The problem is that labels and values needs to be shown in ratios like 10:1, 8:1 etc. but actual bar height shown as numbers 10, 8 etc. Is there any way to create custom labels on y axis and on mouse over tool-tips in nvd3?
回答1:
You can do this using tickFormat (which is actually a raw D3 method):
chart.yAxis
.tickFormat(function (d) {
return d + ':' + 1;
});
NVD3 will automatically use that format in the tooltip.
If you wanted to edit the tooltip content separately you could use the tooltipContent method (other methods will likely be added in the next release of NVD3).
chart.tooltipContent(function (key, x, y, e, graph) {
return '<h3>' + key + '</h3>' +
'<p>' + y + ' on ' + x + '</p>';
});
See this Plunker.
来源:https://stackoverflow.com/questions/29694406/howto-set-custom-ticks-and-labels-on-y-axis-in-nvd3