79111162

Date: 2024-10-21 17:42:55
Score: 0.5
Natty:
Report link

The JS syntax provided by @daniel_s is the solution to this problem. However, this syntax does not allow for dynamic data inputs into the drilldown series, which OP indicates was required, and which I imagine other R users would also require.

For this reason, I provide the following complete code block, which generates a multi series drilldown using different series types, as seen below.

Multiseries drilldown in highcharter

df <- data_frame(
  name = c("Animals", "Fruits", "Cars"),
  y = c(5, 2, 4),
  drilldown = c('animals','','')
)
dfan1 <- data_frame(
  name = c("Cats", "Dogs", "Cows", "Sheep", "Pigs"),
  value = c(4, 3, 1, 2, 1)
)
dfan2 <- data_frame(
  name = c("Cats", "Dogs", "Cows", "Sheep", "Pigs"),
  low = c(3.5,2.5,.5,1.5,.5),
  high= c(4.5,3.5,1.5,2.5,1.5)
)
list1 <- toString(
  lapply(
    1:nrow(dfan1), function(n) {
      paste0("['",dfan1[n,'name'],"',",dfan1[n,'value'],"]")
    }
  )
)
list2 <- toString(
  lapply(
    1:nrow(dfan2), function(n) {
      paste0("['",dfan2[n,'name'],"',",dfan2[n,'low'],",",dfan2[n,'high'],"]")
    }
  )
)
hc <- highchart() %>%
  hc_title(text = "Basic multi series drilldown") %>%
  hc_xAxis(type = "category") %>%
  hc_legend(enabled = FALSE) %>%
  hc_plotOptions(
    series = list(
      boderWidth = 0,
      dataLabels = list(enabled = TRUE)
    )
  ) %>%
  hc_add_series(
    data = df,
    name = "Things",
    colorByPoint = TRUE
  ) %>%
  hc_chart(events = list(
    drilldown = JS(paste0(
      "function(e) {
        if(!e.seriesOptions){
        var chart=this,
        drilldowns={
          'Animals':{
            name:'Animals',
            data:[",list1,"],
            type:'bar'
          },
          'Animals2':{
            name:'Animals',color:'#f00',
            data:[",list2,"],
            type:'errorbar'
          }
      },

      series=[drilldowns[e.point.name],drilldowns[e.point.name+'2']];
      chart.addSingleSeriesAsDrilldown(e.point,series[0]);
      chart.addSingleSeriesAsDrilldown(e.point,series[1]);
      chart.applyDrilldown()
      }}"
    )
    )
  ))
hc
Reasons:
  • Long answer (-1):
  • Has code block (-0.5):
  • User mentioned (1): @daniel_s
  • Low reputation (1):
Posted by: tibblah