2016-06-10 65 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