سؤال

I'm trying to make a toggleable axis using nvd3s charts, specifically the line chart example. After running this example, opening the console, and typing chart.setXAxis(false) the x axis does not hide. Is there some documentation or some reason why this isn't working? It doesn't seem to work for any boolean either.. once it's true, it's not changeable to false.

هل كانت مفيدة؟

المحلول

setXAxis just tells the chart function whether or not to draw the axis when it draws the chart, it doesn't do anything to the existing axis. You'd be better off just selecting the axis directly and changing its visibility style.

Given the class names that NVD3 uses for it's axes, to hide the x-axis you would use:

d3.select("g.nv-axis.nv-x").style("visibility", "hidden")

That hides the axis, but doesn't delete it, so you can easily re-show it again (without updating the chart) with the same select statement but visibility style visible.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top