【问题标题】:Highcharts (rCharts) onclick tooltipHighcharts (rCharts) onclick 工具提示
【发布时间】:2023-03-28 14:16:01
【问题描述】:

我正在尝试重现此 jsfiddle,其中工具提示仅在单击该点时出现:

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

我很确定问题出在 rCharts 无法理解的 JS 部分。有任何想法吗?帮助?

谢谢,

卡洛斯

【问题讨论】:

    标签: r highcharts rcharts


    【解决方案1】:

    你的代码有几个错误:

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

    2. a$plotOptions(events = 必须是 a$plotOptions(series = list(events = 或者您可以使用其他系列类型名称来代替 series,但 series 适用于所有系列类型。

    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
    

    【讨论】:

    • 非常感谢!顺便问一下,正确打印度数符号 º 的诀窍是什么?
    • @Carlos 欢迎您。您可以将工具提示设置为:a$tooltip(valueSuffix = " &amp;deg;C", enabled = F, useHTML = T )
    猜你喜欢
    • 1970-01-01
    • 2022-07-14
    • 2023-03-18
    • 2013-07-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-04
    • 1970-01-01
    相关资源
    最近更新 更多