如何获取highcharts点击事件中点击的图表的值

如何获取highcharts点击事件中点击的图表的值,highcharts,Highcharts,如何获取highcharts点击事件中点击的图表的值 "series": [ { "name": "Requests", "colorByPoint": true, "data": [ { "name": "Pending", "y": 62, "drill

如何获取highcharts点击事件中点击的图表的值

 "series": [
        {
            "name": "Requests",
            "colorByPoint": true,
            "data": [
                {
                    "name": "Pending",
                    "y": 62,
                    "drilldown": "Pending"
                },
                {
                    "name": "Completed",
                    "y": 20,
                    "drilldown": "Completed"
                },
                {
                    "name": "Rejected",
                    "y": 18,
                    "drilldown": "Rejected"
                },
            ]
        }
    ],
    "drilldown": {
        "series": [
            {
                "name": "Requests",
                "id": "Pending",
                "data": [
                    [
                        "New Version",
                        21
                    ],
                    [
                        "HotFixes",
                        13
                    ],
                        ],
                  point: {
                        events: {
                                click: function() {
                                        alert("here we are");
                                }
                        }
                        }

            },

这里假设我点击了“新版本”,那么我如何才能在点击“新版本”的点击事件中获取值。

您需要将函数粘贴到
plotOptions
中,而不是在
系列中,而只是在主配置中

 plotOptions: {
        series: {
            cursor: 'pointer',
            point: {
                events: {
                    click: function () {
                        alert('Category: ' + this.category + ', value: ' + this.y);
                    }
                }
            }
        }
    },
这会在单击时通知给定类别,加上y值

您可以在中找到更多信息。此API还链接到演示如何使用警报函数

总之,您的代码应该是这样的(即使您给我们的不是完整的代码)。您可能需要稍微更改警报功能,以准确显示所需内容

 plotOptions: {
        series: {
            cursor: 'pointer',
            point: {
                events: {
                    click: function () {
                        alert('Category: ' + this.category + ', value: ' + this.y);
                    }
                }
            }
        }
    },
 "series": [
    {
        "name": "Requests",
        "colorByPoint": true,
        "data": [
            {
                "name": "Pending",
                "y": 62,
                "drilldown": "Pending"
            },
            {
                "name": "Completed",
                "y": 20,
                "drilldown": "Completed"
            },
            {
                "name": "Rejected",
                "y": 18,
                "drilldown": "Rejected"
            },
        ]
    }
],
"drilldown": {
    "series": [
        {
            "name": "Requests",
            "id": "Pending",
            "data": [
                [
                    "New Version",
                    21
                ],
                [
                    "HotFixes",
                    13
                ],
                    ],
        },