2

I'm using Highcharts in R, and I want to format the number in the tooltip as a currency without decimal spaces. Right now, numbers appear like this: 34 537 987.21. I want that number to look like this: $34,537,987. Or, better yet, like this: $34M.

Here's a sample of my code:


highchart() %>%
  hc_add_series(df, 
                type = 'spline', 
                hcaes(x = year, y = data)
                ) %>%
  hc_add_series(df, 
                type = 'spline', 
                hcaes(x = year, y = other_data)
                ) %>%
  hc_plotOptions(series = list(marker = list(enabled = TRUE,
                                             hover = TRUE,
                                             symbol = 'circle'))
                ) %>%
  hc_tooltip(
    shared = TRUE,
    crosshairs = TRUE
    )

  • Here is a similar topic: [SO](https://stackoverflow.com/questions/57886804/highcharts-r-show-tooltip-values-in-million-billion-etc-automatically) about changing showing value at tooltip, have you checked it? – Sebastian Hajdus Jun 03 '22 at 09:07

1 Answers1

1

Use the tooltip parameter inside hc_ad_series() and define as shown below.

highchart() %>%
  hc_add_series(df, 
                type = 'spline', 
                hcaes(x = year, y = data),
tooltip = list(pointFormat = "$ {point.data}")
                ) %>%
  hc_add_series(df, 
                type = 'spline', 
                hcaes(x = year, y = other_data),
tooltip = list(pointFormat = "$ {point.other_data}")
                ) %>%
  hc_plotOptions(series = list(marker = list(enabled = TRUE,
                                             hover = TRUE,
                                             symbol = 'circle'))
                )

Hope it helps.

Asitav Sen
  • 56
  • 4