0

I am trying to create a simple semicircle donut using rCharts and the NVD3 javascript library. A minimum reproducible example of a full donut is provided below.

library(rCharts)
data1 <- data.frame(label=c("A","B","C"), value=c("1000","2000","3000"))
n1 <- nPlot(value~label, data = data1, type = "pieChart")
n1$chart(donut=TRUE)
n1

My problem arises when I try to specify the startAngle and endAngle options as provided here in the NVD3 documentation, in order to convert this donut into a semicircle donut.

# This gives me a blank Viewer pane
n1$chart(donut=TRUE,
         startAngle="#!function(d){return d.startAngle/2-Math.PI/2;}!#",
         endAngle="#!function(d){return d.endAngle/2-Math.PI/2;}!#")
n1

Looking at code from this question, it appears that passing startAngle and endAngle to the n1$params$chart may not be the right way to do this, although that is what I would expect based on the fact that donut=TRUE works.

It is also possible that one of my callback functions has improper syntax - in my experience, this sort of problem can crash entire visualizations. However, I am fairly certain that I have used exactly the same callback function provided in the NVD3 documentation.

Community
  • 1
  • 1
aashanand
  • 714
  • 1
  • 6
  • 15

1 Answers1

1

The rCharts library does not allow you to do this as is. I forked it and modified it to include the latest nvd3 JavaScript and added the possibility to add parameters to chart.pie via the .$pie function in R.

You can grab the rCharts fork here: https://github.com/clecocel/rCharts

For a minimum example based on rCharts' quickstart:

p5 <- nPlot(~ cyl, data = mtcars, type = 'pieChart')
p5

You'll see that the growOnHover option is now activated by default.

To create a half donut you can now indeed use:

p5$chart(donut=T)
p5$pie(startAngle="#!function(d){return d.startAngle/2-Math.PI/2;}!#",
       endAngle="#!function(d){return d.endAngle/2-Math.PI/2;}!#"))
Clecocel
  • 96
  • 2