highcharts 网络图表上的自定义悬停/工具提示数据

Custom hover / tooltip data on highcharts network chart

我正在尝试在包含节点 id 以及 [=25= 中的 titleother 字段的 React Highcharts 网络图表上显示自定义工具提示] 数据我正在喂它。但是,我无法使用 API.

中指定的格式化函数使其工作

我的简化代码如下:

import React, { useState, useEffect, useRef } from 'react';
import Highcharts from 'highcharts';
import HighchartsReact from 'highcharts-react-official';

import networkgraph from "highcharts/modules/networkgraph";
networkgraph(Highcharts);

const NetworkChart = () => {

    const chartComponent = useRef(null); // reference to chart obj 
    const [nodeData, setNodeData] = useState([
        { 'id': 'A', title:'ABC', other:'X', dataLabels: { enabled: true }, marker: { radius: 11, fillColor: 'red' } },
        { 'id': 'P', title:'CDE', other:'Y', dataLabels: { enabled: true } },
        { 'id': 'K', title:'EDF', other:'X', dataLabels: { enabled: true } },
        { 'id': 'S', title:'DFG', other:'Z', dataLabels: { enabled: true } },
        { 'id': 'D', title:'SDF', other:'Y', dataLabels: { enabled: true } },
    ]);

    const [linkData, setLinkData] = useState([
        { 'from': 'D', 'to': 'A' },
        { 'from': 'S', 'to': 'A' },
        { 'from': 'K', 'to': 'A' },
        { 'from': 'P', 'to': 'A' }
    ]);


    const [chartOptions, setChartOptions] = useState({
        chart: {
            type: 'networkgraph',
            plotBorderWidth: 1,
        },
        title: {
            text: 'Phrasal verbs'
        },
        subtitle: {
            text: 'Integration: ' + 'euler'
        },
        credits: false,
        plotOptions: {
            networkgraph: {
                layoutAlgorithm: {
                    enableSimulation: false,
                    integration: 'euler',
                    linkLength: 25,
                },
                keys: ['from', 'to'],
                marker: {
                    radius: 5,
                    lineWidth: 1
                }
            },
            series: {
                point: {
                    events: {
                        click: function () {
                            // click function
                            },
                    }
                }
            }
        },
        series: [{
            allowPointSelect: true,
            nodes: nodeData,
            data: linkData,
        }]
    });

    
    return (
        <div>
            <HighchartsReact
                highcharts={Highcharts}
                options={chartOptions}
                containerProps={{ style: { height: 700 } }}
                allowChartUpdate = {true}
                ref={chartComponent}
            />
        </div>
    )
};

export default NetworkChart;

目前我只看到悬停的节点 id。当我将鼠标悬停在图表中的每个节点上时,我想看到的是节点 idtitleother 字段值。

您可以通过以下方式获取所需的属性:this.point.options

    tooltip: {
        formatter: function() {
            const { title, other } = this.point.options;

            return 'Title: ' + title + ' Other: ' + other
        }
    }

现场演示: http://jsfiddle.net/BlackLabel/4zgrnqc2/

API参考:https://api.highcharts.com/highcharts/tooltip.formatter