3

I'm trying to setup a treemap with three levels, using hctreemap2 function. I wanted to embed a hyperlink href when user clicked through at the very last layer(level).

Unlike the typical highchart() %>% hc_add_series(type = "treemap"), which is a flat treemap, this hctreemap function provides for drilldown to multi-levels. However, the codes I have copied from this answer only worked for those with one-layer: Hyperlink bar chart in Highcharter

Please help.

tried the codes from this answer: Hyperlink bar chart in Highcharter

data("GNI2014")

hctreemap2(data = GNI2014,
           group_vars = c("continent",
                          "country"),
           size_var = "population",
           color_var = "GNI",
           layoutAlgorithm = "squarified",
           levelIsConstant = FALSE,
           levels = list(
             list(level = 1, dataLabels = list(enabled = TRUE)),
             list(level = 2, dataLabels = list(enabled = FALSE))
           )) %>%
  hc_legend(FALSE) %>%
  hc_plotOptions(
    series = list(cursor = "pointer",
                  point = list(
                    events = list(
                      click = JS("function () {location.href = 'https://en.wikipedia.org/wiki/' + this.options.country;}")))))

Hyperlink to only be activated when drilldown to the lowest level, aka "country". However, the hyperlink is activated the moment I drill.

(Beginner level programmer here, and nor can I find anything useful from the API site: https://api.highcharts.com/highcharts/

data("GNI2014")

hctreemap2(data = GNI2014,
           group_vars = c("continent",
                          "country"),
           size_var = "population",
           color_var = "GNI",
           layoutAlgorithm = "squarified",
           levelIsConstant = FALSE,
           levels = list(
             list(level = 1, dataLabels = list(enabled = TRUE)),
             list(level = 2, dataLabels = list(enabled = FALSE))
           )) %>%
  hc_legend(FALSE) %>%
  hc_plotOptions(
    series = list(cursor = "pointer",
                  point = list(
                    events = list(
                      click = JS("function () {location.href = 'https://en.wikipedia.org/wiki/' + this.options.country;}")))))

Chee Teoh
  • 31
  • 1

0 Answers0