jbkunst / highcharter

R wrapper for highcharts
http://jkunst.com/highcharter/
Other
720 stars 148 forks source link

Highchart 3D barchart not able to display bars for 1 category in the x-axis. #690

Closed akshaybholee closed 2 years ago

akshaybholee commented 3 years ago

Hello there,

I am trying to produce 3d barchart with highcharter with z-axis label and x-axis label showing. But when my dataframe has only one row the chart doesnot display the bars. If the dataframe consist of more than one row it displays properly.

I want to be able to display 1 row from the dataframe also in the chart.

Below is a reproducible example:

library(shiny)
library(highcharter)

shinyApp(

  ui <- fluidPage(
    fluidRow(
      highchartOutput('chart')
    )
  ),

  server <- function(input, output, session) {

    df <- data.frame(
      Z1 = c(1, 2, 1, 4),
      Z2 = c(2, 3, 2, 7),
      Z3 = c(6, 3, 7, 4),
      Z4 = c(3, 4, 1, 5)
    )

    df <- df[-(1:3),] #reduced dataframe to 1 row

    dta <- lapply(seq(ncol(df)), function(x) {
      list(
        name = colnames(df)[x], 
        data = df[, x]
      ) 
    })

    output$chart <- renderHighchart({

      highchart() %>%
        hc_chart(
          type = "column", 
          options3d = list(
            enabled = TRUE,
            beta = 20,
            alpha = 30,
            depth = 400,
            viewDistance = 10
          )
        ) %>%
        hc_xAxis(categories = row.names(df[1:nrow(df)-1,])) %>%
        hc_zAxis(
          min = 0,
          max = 3,
          categories = colnames(df)
        ) %>%
        hc_plotOptions(
          series = list(
            depth = 100,
            grouping = FALSE,
            groupZpadding = 10
          )
        ) %>%
        hc_add_series_list(dta)
    })
  })

insert reprex here

stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. Feel free to reopen it if you find it necessary.