所以我有一个有趣的问题。
这是格式化程序函数位于图表配置对象内部的位置:
在 HighCharts Controller 中
vm.config = {
options: {
....
chart: {
....
},
navigator: {
....
},
tooltip: {
shared: true,
useHTML: true,
backgroundColor: null,
borderWidth: 0,
shadow: false,
formatter: function(tooltipObj) {
return formatTooltip(tooltipObj, this.points);
}
},
....
我希望能够从应用程序中的其他位置调用 formatTooltip
函数。但是,1)我该怎么做? 2) 如何传入 tooltipObj
?
例如,在我的alertFactory内部,我希望当用户将鼠标悬停在plotBand上时发生鼠标悬停事件,以将更多信息发送到工具提示中:
在 AlertsFactory 中
var formatPlotBand = _.curry((color, alert) => {
return {
color : color,
from : alert.start_epoch * 1000,
to : alert.end_epoch * 1000,
id :'alert-plotband',
events: {
mouseover: function (e) {
/*
Somehow from here call the formatTooltip function
in the highCharts Controller.
*/
},
mouseout: function (e) {
....
最佳答案
var formatPlotBand = _.curry((color, alert) => {
return {
color : color,
from : alert.start_epoch * 1000,
to : alert.end_epoch * 1000,
id :'alert-plotband',
events: {
mouseover: function (e) {
vm.config.options.tooltip.formatter(tooltipObj);
chart.tooltip.refresh([chart.series[0].points[i]])
},
mouseout: function (e) {
....
我不知道 vm
是否是您对图表的调用,因此请将代码中的 chart
替换为您使用的任何变量名称。
关于javascript - 如何从配置对象外部调用 Highcharts 工具提示格式化程序函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38702428/