在每个节点上悬停时带有工具提示的Highchart网络图

时间:2019-05-05 18:59:37

标签: javascript highcharts highcharts-ng angular2-highcharts

我正在为我的Angular项目之一使用highcharts创建网络图。我想在鼠标移至点/节点时创建工具提示。我试图使用下面的图表选项创建。但是,我遇到了错误。如何为网络图点创建工具提示?

 chartOptions = {
  chart: {
    type: "networkgraph",
    height: "100%"      
  },
  title: {
    text: "Network graph demo"
  },
  subtitle: {
    text: "A Force-Directed Network Graph in Highcharts"
  },
  plotOptions: {
    networkgraph: {
      keys: ["from", "to"],
      layoutAlgorithm: {
        enableSimulation:true
      }
    }

  },
  series: [
    {
      dataLabels: {
        enabled: true,            
        linkFormat: ''          
      },
      data: [{from : 'a', to: 'b'},
              {from: 'a', to: 'c'},
               {from: 'a', to: 'd'} ],
      marker : {radius : 18}
    }

  ],
  tooltip :
   {
    enabled : true, 
    formatter : { function() {
      return "<div> <span> My tooltip information </span> </div>"
    }}
  }
}

错误:

 ERROR TypeError: w.call is not a function
at a.Tooltip.refresh (highcharts.js:205)
at a.Pointer.runPointActions (highcharts.js:220)
at q.onMouseOver (highcharts.js:446)
at SVGGElement.d [as __zone_symbol__ON_PROPERTYmouseover] (highcharts.js:435)
at SVGGElement.wrapFn (zone.js:1332)
at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (zone.js:423)
at Object.onInvokeTask (core.js:17290)
at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (zone.js:422)
at Zone.push../node_modules/zone.js/dist/zone.js.Zone.runTask (zone.js:195)
at ZoneTask.push../node_modules/zone.js/dist/zone.js.ZoneTask.invokeTask [as invoke] (zone.js:498)

2 个答案:

答案 0 :(得分:1)

工具提示似乎错误。 (大括号)

尝试此代码:

 tooltip :
   {
    enabled : true, 
    formatter : function() {
      return "<div> <span> My tooltip information </span> </div>"
    }
  }

答案 1 :(得分:1)

我认为问题可能是chartOptions

首先,我实现了键和值的引号,并将单引号替换为双引号。

第二,我认为它期望一个函数,而不是formatter的对象;因此,从此:

"formatter" : {function() {
      return "<div> <span> My tooltip information </span> </div>"
    }}

我更改为:

"formatter" : function() {
      return "<div> <span> My tooltip information </span> </div>"
    }

这是整件事:

chartOptions = {
  "chart": {
    "type": "networkgraph",
    "height": "100%"      
  },
  "title": {
    "text": "Network graph demo"
  },
  "subtitle": {
    "text": "A Force-Directed Network Graph in Highcharts"
  },
  "plotOptions": {
    "networkgraph": {
      "keys": ["from", "to"],
      "layoutAlgorithm": {
        "enableSimulation":true
      }
    }

  },
  "series": [
    {
      "dataLabels": {
        "enabled": true,            
        "linkFormat": ""          
      },
      "data": [{"from" : "a", "to": "b"},
              {"from": "a", "to": "c"},
               {"from": "a", "to": "d"} ],
      "marker" : {"radius" : 18}
    }

  ],
  "tooltip" :
   {
    "enabled" : true, 
    "formatter" : function() {
      return "<div> <span> My tooltip information </span> </div>"
    }
  }
}

尝试一下,让我知道是否继续这样做。

如果您可以将其放入Stack Overflow提供的Snipped中,则更容易尝试和提供帮助。片段是图标enter image description here