Home > Net >  How to put value on highcharts compare option in R
How to put value on highcharts compare option in R

Time:06-08

I have this code

serie <- data.frame(date=c("2022-01-01","2022-01-02","2022-01-03"),serie2=c(1,2,5), serie3=c(4,6,7))
serie$date <- as.Date(serie$date)
serie <- tk_xts(serie,data_var = serie$date)

highchart(type = "stock") %>%
  hc_title(text = "Comparison") %>%
  hc_add_series(serie$serie2,
                name = "serie 2",
                color = "green", compare = 'percent', compareBase=100) %>%
  hc_add_series(serie$serie3, name = "serie 3", color= "white",compare = 'percent', compareBase=100)%>%
  hc_add_theme(hc_theme_db())%>%
  hc_navigator(enabled = FALSE) %>%
  hc_scrollbar(enabled = FALSE) %>%
  hc_legend(enabled = TRUE) %>%
  hc_exporting(enabled = TRUE) %>%
  hc_xAxis(
    labels = list(
      style = list(
        color = "white"
      )
    )
  ) %>%
  hc_yAxis(
    labels = list(format = '{value}%',
                  style = list(
                    color = "white"
                  )
    )
  )

I need to get this value in R-highcharts. I saw this enter image description here

CodePudding user response:

It's a bit difficult to determine what you are asking for. I think that you're looking to have the tooltips modified, so they match how they are documented in this plot. If so, you can use

hc_tooltip(pointFormat = paste0('<span style="color:{series.color}">{series.name}',
                                '</span>: <b>{point.y}</b> ({point.change}%)<br/>'),
           valueDecimals = 2,
           split = T)

Your y-axis is unlabeled, but you have code for formatting it. If you want your y-axis formatted like this plot, you can use

hc_yAxis(formatter = "function(){
           return (this.value > 0 ? '   ' : '')   this.value   '%';
           }")

Let me know if there's anything else.

  • Related