Using Joshua Kunt's Highcharter R package, I'm trying to add a custom tooltip and format numbers so thousands have a comma separator. The Y axis and tooltips format correctly if I don't customize the tooltip, when I use the following code:
snow <- read.csv("https://gist.githubusercontent.com/smach/d4188d200b465cba822405c323f1501c/raw/58c3785c34304ccc5dbcef632d3acb9d6dbad40c/BosChiNYCsnowfalls.csv", stringsAsFactors = FALSE)
library("highcharter")
hcoptslang <- getOption("highcharter.lang")
hcoptslang$thousandsSep <- ","
options(highcharter.lang = hcoptslang)
highchart() %>%
hc_chart(type = "line") %>%
hc_title(text = "Snowfall") %>%
hc_xAxis(categories = snow$Winter) %>%
hc_add_series(data = snow$Boston * 10, name = "Boston") %>%
hc_yAxis(labels = list(format = "{value:,.0f}"))
However, once I add a formatter like
hc_tooltip(formatter = JS("function () { return '<b>' + this.series.name + '</b><br /> ' + this.point.y + ' <br />' + this.x;}"))
The tooltip number no longer has the comma. I think there's something I need to do to this.point.y
in the formatter, but the few things I've tried haven't worked. Does anyone know what I need to add to the formatter function to make the tooltip also display the comma for the y value? Thanks.