有条件地 show/hide Highcharter 的工具提示

Conditionally show/hide Tooltip of Highcharter

我正在绘制一个简单的 Highchart Area 图,我想根据基础系列的某些值有条件地 show/hide 工具提示(在下面的情况下,它基于 [=12= 的值) ])

下面是我的 R 代码:

library(highcharter)
highchart() %>%  
hc_chart(type = "area", plotBorderWidth = 0.5, plotBorderColor = '#4572A7') %>%    # https://gist.github.com/mulhoon/63b5d5a98ef0ab8c2b89
hc_xAxis(categories = as.character(c(1.00, 2.00, 3.00)), lineWidth = 1, gridLineWidth = 0, minorGridLineWidth = 0) %>%
hc_xAxis(lineWidth = 1, gridLineWidth = 0, minorGridLineWidth = 0, labels = list(format = '{value}%')) %>%  # 
hc_add_series(name = 'foo', data = list(list(y = 3, z = 1), list(y = 4, z = 0), list(y = 5, z = 1))) %>%
hc_tooltip(formatter = "function(){

                if (this.point.z == 1) {
                    return 'ON';
                }
            }") %>%
hc_plotOptions(series = list(marker = list(enabled = 'false', radius = 1, states = list(hover = list(enabled = 'false', radius = .1, color = '#4572A7')))))

基本上,我想要的是:当值为z = 1时显示Tooltip,否则不显示。但是上面的代码失败了,因为它根本没有显示工具提示。

关于如何实现工具提示的上述条件显示有什么想法吗?

感谢您的指点。

我修改了格式化程序参数后的代码以满足您的需要。

library(highcharter)
highchart() %>%  
  hc_chart(type = "area", plotBorderWidth = 0.5, plotBorderColor = '#4572A7') %>%    # https://gist.github.com/mulhoon/63b5d5a98ef0ab8c2b89
  hc_xAxis(categories = as.character(c(1.00, 2.00, 3.00)), lineWidth = 1, gridLineWidth = 0, minorGridLineWidth = 0) %>%
  hc_xAxis(lineWidth = 1, gridLineWidth = 0, minorGridLineWidth = 0, labels = list(format = '{value}%')) %>%  # 
  hc_add_series(name = 'foo', data = list(list(y = 3, z = 1), list(y = 4, z = 0), list(y = 5, z = 1))) %>%
  hc_tooltip(formatter = JS("function(){

             if (this.point.z == 1) {
             return 'ON';
             } else { 
              return false;
             }
             }")) %>%
hc_plotOptions(series = list(marker = list(enabled = 'false', radius = 1, states = list(hover = list(enabled = 'false', radius = .1, color = '#4572A7')))))