Howto set custom ticks and labels on Y axis in nvd3

泪湿孤枕 提交于 2020-01-17 04:25:47

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!