如何在工具提示中访问系列数据

时间:2018-12-28 13:06:26

标签: javascript html highcharts

我正在使用highcharts网络图,我想访问数据中存在的value字段以将其悬停在节点上时显示它。我无法使用this.point.value来访问它。有人可以帮助我解决此问题吗?

这是我的代码:

tooltip: {
  formatter: function () {
    return '<b>' + 'Tree' + '</b><br>' +
      'Name: ' + this.point.name + '<br>' +
      'Description: ' + this.point.value;
  }
},

series: [{
  dataLabels: {
    enabled: true
  },
  data: [
    {
      from: 'location',
      to: 'addr',
      value: 'This is sample data'
    }
  ]
}]

1 个答案:

答案 0 :(得分:0)

您可以使用this.point.linksFrom[0].value访问它。检查下面发布的代码和演示。

代码:

Highcharts.chart('container', {
  chart: {
    type: 'networkgraph'
  },
  tooltip: {
    formatter: function() {
      var text = '<b>' + 'Tree' + '</b><br>' +
        'Name: ' + this.point.name + '<br>';

      if (this.point.linksFrom[0]) {
        text += 'Description: ' + this.point.linksFrom[0].value;
      }

      return text;
    }
  },
  series: [{
    dataLabels: {
      enabled: true
    },
    data: [{
      from: 'location',
      to: 'addr',
      value: 'This is sample data'
    }, {
      from: 'point2',
      to: 'addr',
      value: 'Another data'
    }]
  }]
});

演示:
https://jsfiddle.net/BlackLabel/cohnks96/1/