HighCharts(iOS) - 如何默认仅在某些位置显示工具提示

HighCharts(iOS) -How to show tooltip by default at only some positions

HighCharts(iOS): 如何通过在 swift 中传递索引,默认仅在某些位置显示工具提示,在中找到以下示例javascript

let chart = Highcharts.chart('container', {
  chart: {
    events: {
      load() {
        this.tooltip.refresh(this.series[0].points[2]);
        this.tooltip.refresh(this.series[0].points[4]);
      }
    }
  },
  tooltip: {
    formatter: function() {
      return '3';
    }
  },

试过这样的东西

chart.events.load = tooltip.refresh(by: tooltipFunction)

任何人都可以将 javascript 转换为 swift(iOS)

演示在 javascript

https://jsfiddle.net/BlackLabel/mqz3Ljy6/

下面是所需结果的工作代码:

let options = HIOptions()

let chart = HIChart()
chart.events = HIEvents()
chart.events.load = HIFunction(jsFunction: "function() { this.tooltip.refresh(this.series[0].points[2]); this.tooltip.refresh(this.series[0].points[4]); this.tooltip.refresh(this.series[0].points[6]); }")
options.chart = chart

let tooltip = HITooltip()
tooltip.formatter = HIFunction(jsFunction: "function() { return '...'; }")
options.tooltip = tooltip

let plotOptions = HIPlotOptions()
plotOptions.column = HIColumn()
plotOptions.column.point = HIPoint()
plotOptions.column.point.events = HIEvents()
plotOptions.column.point.events.mouseOver = HIFunction(jsFunction: "function() { let tooltip = chart.tooltip; tooltip.update({ formatter: function() { return 'New content!' } }) }")
options.plotOptions = plotOptions

let column = HIColumn()
column.data = [4, 3, 5, 6, 2, 3, 7, 9, 12, 15, 2, 4, 6]
options.series = [column]

接受的答案略有变化,因为图表需要很少的时间加载,因此设置 200 毫秒的超时,如果数据更多,相应地增加时间

let options = HIOptions()

let chart = HIChart()
chart.events = HIEvents()
chart.events.load = HIFunction(jsFunction: "function() { var self = this; setTimeout(function(){ self.tooltip.refresh(self.series[0].points[2]); }, 200); }")
options.chart = chart

let tooltip = HITooltip()
tooltip.formatter = HIFunction(jsFunction: "function() { return '...'; }")
options.tooltip = tooltip

let plotOptions = HIPlotOptions()
plotOptions.column = HIColumn()
plotOptions.column.point = HIPoint()
plotOptions.column.point.events = HIEvents()
plotOptions.column.point.events.mouseOver = HIFunction(jsFunction: "function() { let tooltip = chart.tooltip; tooltip.update({ formatter: function() { return 'New content!' } }) }")
options.plotOptions = plotOptions

let column = HIColumn()
column.data = [4, 3, 5, 6, 2, 3, 7, 9, 12, 15, 2, 4, 6]
options.series = [column]