HighChart networkgraph 自定义关系format 节点format

最近使用neo4j,前端使用highchart做成dashboard,需要用到这些,直接从官网api上来找是没问题,但是就是他的property太多了,找半天,特别是你还不知道那个property叫什么名字的时候.所以总结下,下次就懒得去找了
这个官网api的链接https://api.highcharts.com/highcharts/

自定义关系format 与节点format

series.dataLabels.linkFormatter
series.dataLabels.formatter

首先要先启用datalabel

export const CHART_SRC = {
  chart: {
    type: 'networkgraph',
    height: 800,
    width: 2000
  },
  exporting: {
    enabled: false
  },
  scrollbar: {
    enabled: true
  },
  title: null,
  credits: {
    enabled: false
  },
  plotOptions: {
    networkgraph: {
      keys: ['from', 'to', 'custom'],
      layoutAlgorithm: {
        enableSimulation: false,
        friction: -0.96,
        linkLength: 60
        // integration: 'verlet'
      },
      cursor: 'pointer',
      events: {}
    }
  },
  series: [
    {
      dataLabels: {
        enabled: true,
        linkTextPath: {
          attributes: {
            dy: 12
          }
        },
        // eslint-disable-next-line object-shorthand
        linkFormatter: function () {
          return this.point.options.relationship + '<br>' + this.point.fromNode.id + '\u2192' + this.point.toNode.id;
        },
        // eslint-disable-next-line object-shorthand
        formatter: function () {
          return  this.point.id + ' . ' + this.point.custom.view.view_name + '<br> ' + this.point.custom.view.view_description;
        },
      },
      marker: {
        radius: 25
      },
      color: 'rgb(124, 181, 236)',
      data: []
    }
  ]
}

这两个都是函数,可以自定义拼接你需要的值,我试了一下<br>可以起到换行的效果但是似乎加什么<h2>之类的就不生效了.

不知道这里面this里面到底什么结构? 没关系,用chrome debug一下就知道了,比去官网看直观多了
在这里插入图片描述

自定义数据

要是因为from to作为id不够进行展示的话,还可以用一下结构

data:[
	{from:1,to:2}
],
nodes:[
	{id:1,name:'xxxx',custom:'xxxxxxx'}
]

他会把from1 这个节点自动匹配nodes的id为1的节点,custom是我自定义的字段,里面放这个node更加详细的detail

click事件

我的click事件是写在component里面的(我是用的是angular10,以及angular-highcharts)

    this.chartStr['plotOptions']['networkgraph']['events'] = {
      click: (event: any) => {
        this.nodeDetail = event['point']['custom']['detail'];
        this.dialogTitle = event['point']['name'];
        this.dialogDisplay = true;
      }
    }

这时候我就可以拿到关于当前node的详细信息用于放进dialog进行展示了,这个this.chartStr就是一开始展示的json

展示

涉及到数据敏感,就只展示一小部分无关紧要的数据
在这里插入图片描述
在这里插入图片描述

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值