2016-06-10 68 views
2

我试图重现此的jsfiddle其中仅提示单击该点时出现:Highcharts(rCharts)的onclick提示

http://jsfiddle.net/2swEQ/2/

这是我的 “翻译” 成rCharts:

a <- rCharts::Highcharts$new() 

a$xAxis(categories = c("Jan", "Feb", "Mar", "Apr", "May", "Jun", 
         "Jul", "Aug", "Sep", "Oct", "Nov", "Dec")) 

a$tooltip(valueSuffix = " ºC", 
      enabled = F) 

a$chart(list(events = list(load = "#! function() 
            this.myTooltip = new Highcharts.Tooltip(this, this.options.tooltip) !#")))      

a$plotOptions(events = list(click = "#! function(evt) 
             this.chart.myTooltip.refresh(evt.point, evt) !#", 
          mouseOut = "#! function() 
             this.chart.myTooltip.hide() !#")) 

a$series(list(
    list(name = "Tokyo", 
     data = c(7.0, 6.9, 9.5, 14.5, 18.2, 21.5, 
       25.2, 26.5, 23.3, 18.3, 13.9, 9.6)))) 

a 

我敢肯定,问题是JS部分是不被rCharts理解。有任何想法吗?帮帮我?

感谢,

卡洛斯

回答

1

有在你的代码一些错误:

  1. a$chart(list(events =应该a$chart(events =相同的结构,在a$xAxis(categories =

  2. a$plotOptions(events =需求是a$plotOptions(series = list(events =或者你可以使用另一个系列类型n艾美而不是系列,但系列适用于所有系列类型。

  3. 所有三个函数都必须使用{}作为每个函数的主体。

工作代码:

a <- rCharts::Highcharts$new() 

a$xAxis(categories = c("Jan", "Feb", "Mar", "Apr", "May", "Jun", 
         "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" 
)) 

a$tooltip(valueSuffix = " ºC", 
      enabled = F 
) 

a$chart(events = list(load = "#! function() { 
      this.myTooltip = new Highcharts.Tooltip(this, this.options.tooltip); 
     } !#" 
)) 

a$plotOptions(series = list(events = list(click = "#! function(evt) { 
      this.chart.myTooltip.refresh(evt.point, evt); 
     } !#", 
     mouseOut = "#! function() { 
      this.chart.myTooltip.hide(); 
     } !#" 
))) 

a$series(list(list(name = "Tokyo", 
        data = c(7.0, 6.9, 9.5, 14.5, 18.2, 21.5, 
          25.2, 26.5, 23.3, 18.3, 13.9, 9.6) 
))) 

a 
+0

非常感谢!顺便说一下,打印度数符号º适当的诀窍是什么? – Carlos

+0

@卡洛斯你不客气。你可以设置工具提示为:'a $ tooltip(valueSuffix =“° C”, enabled = F, useHTML = T )' –

+0

非常感谢。大! – Carlos