dreamRs / apexcharter

:bar_chart: R Htmlwidget for ApexCharts.js
https://dreamrs.github.io/apexcharter
Other
138 stars 15 forks source link

RadialBar using Full API #1

Closed maluta closed 5 years ago

maluta commented 5 years ago

I'd like to create a view using multiple radial bars.

I successfully generate it using the following code:

  s <- c('S1','S2','S3','S4','S5','S6','S7')
    t <- c('100','100','100','50','10','0','0')
    c <- data.frame(s,t)

    apexcharter::apex(data = c, type = "radial",
                      mapping = aes(x = seqs, y = t))

Output:

image

But when I try to use Full API I'm struggling to map the parameters.

The following code isn't working

  apexcharter::apexchart() %>%
      ax_chart(type = "radialBar") %>%
      ax_plotOptions(radial = radialBar_opts(
        size = 6
      )) %>% 
      ax_series(
        list(
          data = t
        )
      ) %>%
      ax_xaxis(categories = s ) %>%
      ax_subtitle(text = "")

I would appreciate any tip in where am I going wrong?

pvictor commented 5 years ago

Hi,

You can use the following :

s <- c('S1','S2','S3','S4','S5','S6','S7')
t <- c('100','100','100','50','10','0','0')

apexchart() %>%
  ax_chart(type = "radialBar") %>%
  ax_plotOptions(radial = radialBar_opts(
    size = 200
  )) %>%
  ax_series2( t ) %>%
  ax_labels2( s ) %>%
  ax_subtitle(text = "")

Full API is close to the JavaScript API, so you can refer to the official documentation : https://apexcharts.com/javascript-chart-demos/radialbar-charts/multiple-radialbars/

Here you have to use ax_series2 and ax_labels2 because data for pie and radial chart use vector and not list for data.

Victor

maluta commented 5 years ago

Thanks Victor!