Skip to content

Custom tooltip for stacked barcharts #29

@u909090

Description

@u909090

Hi,

First of all, thanks for this awesome package !
However, I am having issues customizing the tooltip when making stacked barcharts.

From the example given in the vignette:

library(ggplot2)
library(scales)
library(dplyr)
library(apexcharter)

data("mpg")
n_manufac_year <- count(mpg, manufacturer, year) %>%
group_by(manufacturer) %>% 
mutate(pct = n/sum(n)*100)

apex(data = n_manufac_year, type = "column", mapping = aes(x = manufacturer, y = pct, fill = year)) %>% 
  ax_chart(stacked = TRUE)

How could one display tooltips formatted as below for instance (i.e. containing pct and n values):

dodge
1999: 43.2% (16)
2008: 56.8% (21)

I tried to include a custom formatter but I am afraid I do not get the JS logic

apex(data = n_manufac_year, type = "column", mapping = aes(x = manufacturer, y = pct, fill = year)) %>% 
  ax_chart(stacked = TRUE) %>%
  ax_tooltip(
     y = list(
      formatter = JS("function(value) {return value + '%'}")
    )
  )

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions