Search code examples
htmlhighchartsr-highcharter

Add a colored text in italic to Highchart plot


I want to add a text in italic with blue color using HTML. I used the <em> tag to define italic text and the <span> tag to define a color but i only get the text in italic :
enter image description here

This what i did :

library(highcharter)
library(dplyr)
highchart()%>%
  hc_yAxis(
    title = list(text = "value")
  )%>%
  hc_xAxis(
    accessibility = list(
      rangeDescription = 0:5
    )
  )%>%
  hc_plotOptions(
    series = list(
      labels = list(
        connectorAllowed = FALSE
      ),
      pointStart = 0
    )
  )%>%
  hc_series(
    list(
      type = "spline",
      color = "#0000FF",
      name = 'data',
      data = c(100,92,84,77,71)
    )
    
  )%>%
  hc_labels(
    items = list(
      list(
        html = "<span style=\"color:#0000FF\"><em>a text here in blue color</em></span>",
        style = list(
          left = "144%",
          top = "50%"
        )
      )
    )
  )

Some help would be appreciated


Solution

  • We have to put tag inside list objet. This is the full code :

    library(highcharter)
    library(dplyr)
    highchart()%>%
      hc_yAxis(
        title = list(text = "value")
      )%>%
      hc_xAxis(
        accessibility = list(
          rangeDescription = 0:5
        )
      )%>%
      hc_plotOptions(
        series = list(
          labels = list(
            connectorAllowed = FALSE
          ),
          pointStart = 0
        )
      )%>%
      hc_series(
        list(
          type = "spline",
          color = "#0000FF",
          name = 'data',
          data = c(100,92,84,77,71)
        )
        
      )%>%
      hc_labels(items = list(
        list(html = "<em>a text here in blue color</em>", style = list( color = "#0000FF", left = "144%", top = "50%" ))
        ))