0

I am trying to render an image to display it on my highchart graph in shiny app but am unable to do so.

I tried this:

dataLabels = list(
  enabled = T,
  allowOverlap = T,
  style = list(
    fontWeight = "italic",
    fontSize = 11
  ),
  formatter = JS("
                           function(){
                            return(this.renderer.image('https://www.highcharts.com/samples/graphics/sun.png', 160, 30, 30).add()+
                            '<br>sim API: ' + this.point.sim_api.toFixed(0));
                            }")
)

I expect that in graph the image should appear but it's not appearing.

Navneet
  • 3
  • 3

1 Answers1

0

By using formatter functions, you need to always return a string from it. So, you can use the below approach:

  yAxis: {
    labels: {
      useHTML: true,
      formatter: function() {
        return '<div style="height: 30px; width: 30px; background-image: url(https://www.highcharts.com/samples/graphics/sun.png)"></div>'
      }
    }
  }

Or render an image in some chart event.


Live demo: http://jsfiddle.net/BlackLabel/jpmvhLkx/

API Reference: https://api.highcharts.com/highcharts/yAxis.labels.formatter

ppotaczek
  • 36,341
  • 2
  • 14
  • 24