NVD3 (D3 JS) how to remove y2 axis

落爺英雄遲暮 提交于 2019-11-28 08:47:13

问题


I'm trying to use the following example which is a line and bar chart combined.

NVD3 Line & Bar Chart combination

The problem I have is that I want the line chart and bar chart to both use the same figures from y1 axis, but I can't find out how to get rid of the y2 axis and do this.

If someone could point me in the right direction it'd be a great help.

Thanks in advance.

Edit:

A JSFiddle of the problem I'm experiencing. I'm just using the example from NVD3's download and have added in Lars' code just before the return chart; line.

JSFiddle


回答1:


There's no option to disable the second y axis. What you can do is set it up to have the same scale as the y1 axis and then remove it after creating the graph, i.e.

d3.select('.nv-y2.nv-axis').remove();

This will leave some empty space where the axis used to be, but at least it'll create the impression that there's only one y axis.




回答2:


Much like Lars' answer, this leaves a gap where the axis used to be, but I hid this with CSS.

.y2-axis {display: none}



回答3:


another way to handle is by setting yAxis to false:

var chart = nv.models.discreteBarChart()
            .x(function (d) { return d.label })
            .y(function (d) { return d.value })
            .staggerLabels(false)
            .showYAxis(false)


来源:https://stackoverflow.com/questions/20075708/nvd3-d3-js-how-to-remove-y2-axis

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