jbkunst / highcharter

R wrapper for highcharts
http://jkunst.com/highcharter/
Other
720 stars 148 forks source link

change color of a button #726

Closed learning-freak closed 3 years ago

learning-freak commented 3 years ago

I would like to change the text color and the background color of a button (for example : text in red and background color in blue) using the function navigation (see here : https://api.highcharts.com/highmaps/navigation) but can not find how to do it from highcharter.

Here is my example :

library(highcharter)
# data
df <- data.frame(dose=c("D0.5", "D1", "D2"),
                 len=c(4.2, 10, 29.5))

#graph
df %>%
  hchart('column', hcaes(x = dose, y = len))%>%
  hc_exporting(
    enabled = TRUE,
    buttons = list(
      contextButton = list(
        symbol = NULL,
        menuItems = NULL,
        text = 'mybutton',
        onclick = JS("
                   function() {
            this.exportChart({
              type: 'image/png'
            });
          }

                   ")
      )
    )
  )

How can we change text color and background color of a button with Highcharter ?

jbkunst commented 3 years ago

Hello @learning-freak

  1. Please, first read https://jkunst.com/highcharter/articles/highchartsjs-api-basics.html
  2. Based in the first item, you can to search "theme buttons in highcharts" or "change export button style highcharts".
  3. You'll reach https://api.highcharts.com/highcharts/exporting.buttons.contextButton.theme and http://jsfiddle.net/BlackLabel/udhvazqo/ links.
  4. Based in the previous information modify your R code to match the structure based on point1.
#graph
df %>%
  hchart('column', hcaes(x = dose, y = len))%>%
  hc_exporting(
    enabled = TRUE,
    buttons = list(
      contextButton = list(
        symbol = NULL,
        menuItems = NULL,
        text = 'mybutton',
        onclick = JS("
                   function() {
            this.exportChart({
              type: 'image/png'
            });
          }

                   "),
        theme = list(
          stroke = 'red',
          states = list(
            hover = list(
              fill = "blue"
            )
          )
        )
      )
    )
  ) 

Kind regards