Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display y-axis label for plots based on nvd3? #102

Closed
rob-roesler opened this issue Jun 10, 2013 · 4 comments
Closed

Display y-axis label for plots based on nvd3? #102

rob-roesler opened this issue Jun 10, 2013 · 4 comments

Comments

@rob-roesler
Copy link

Hi,

one question regarding the plot functions using nvd3. How could I display the label of the y-axis? The following simple example only shows the label for the x-axis:

require(rCharts)
tmp <- data.frame(TIME = seq(-5,5,1), VAL = seq(-5,5,1)^2)
p2 <- nPlot(VAL ~ TIME, data = tmp, type = 'lineChart')
p2$params$xAxis = list(axisLabel = "X")
p2$params$yAxis = list(axisLabel = "Y")
p2

The result I'm searching for should be more look like http://nvd3.org/ghpages/line.html

Thanks in advance and btw - very promising package

@ramnathv
Copy link
Owner

Thanks for reporting this issue. I will investigate and post back any solutions I come up with. On a quick note, your usage of the API is incorrect. You cannot access the parameters of the rChart object directly. So your code should read:

require(rCharts)
tmp <- data.frame(TIME = seq(-5,5,1), VAL = seq(-5,5,1)^2)
p2 <- nPlot(VAL ~ TIME, data = tmp, type = 'lineChart')
p2$xAxis(axisLabel = "X")
p2$yAxis(axisLabel = "Y")
p2

I am aware that this does not solve the issue, but just wanted to let you know the correct usage.

UPDATE. @timelyportfolio can you take a look at this when you find the time?

@rob-roesler
Copy link
Author

Thanks for the fast answer. I'm looking forward to the fixed version.

@timelyportfolio
Copy link
Contributor

If you look into it, "Y" is being drawn but at -63 so it falls outside of the bounds of the container. This happens on line 566 of nv.d3.js:

             .attr('y', rotateYLabel ? (-Math.max(margin.left,width) + 12) : -10); //TODO: consider calculating this based on largest tick width... OR at least expose this on chart

I now it is not as clean as we would like but setting a width less than 62 will work, so something like

p2$yAxis(axisLabel = "Y", width = 40)

will work.

@ramnathv
Copy link
Owner

Thanks @timelyportfolio . I would have never figured that one out :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants