gpt4 book ai didi

jquery - HighCharts onclick this.point.name 未定义

转载 作者:行者123 更新时间:2023-12-01 07:08:13 27 4
gpt4 key购买 nike

我想向 HighCharts 饼图添加 onclick 监听器。饼图可以工作,onnclick 也可以工作。我使用返回 json 数据的 php 脚本返回图表的数据。

我遇到的问题是,虽然我可以返回“this.x”和“this.y”值以及“this.series.name”,但我无法返回“this.point”。名称”值。当我尝试时,我可以在 firebug 中看到由于“this.point”未定义而生成错误。此问题的一个示例是,如果我将 Jquery 警报附加到单击事件处理程序,并使用“this.y”,我将返回与工具提示使用的相同值。但是如果我尝试 "this.point.name",它会失败。下面你可以看到我的例子。您可以看到,对于工具提示和数据标签,该值有效,但不适用于系列点事件。有什么想法吗?

这是代码:

$(document).ready(function() {
var options = {
chart: {
renderTo: 'pie_main',
plotBackgroundColor: null,
plotBorderWidth: null,
plotShadow: false
},
title: {
text: 'Values by Type'
},
tooltip: {
formatter: function() {
return '<b>'+ this.point.name +'</b>: '+ this.y;
}
},
plotOptions: {
pie: {
allowPointSelect: true,
cursor: 'pointer',
dataLabels: {
enabled: true,
color: '#000000',
connectorColor: '#000000',
formatter: function() {
return '<b>'+ this.point.name +'</b>: '+ this.y;
}
}
},
series: {
point: {
events: {
click: function () {
alert(this.point.name);
}
}
}
}
},
series: [{
type: 'pie',
name: 'Browser share',
data: []
}]
}

$.getJSON("../php/get_pie_cnts.php", function(json) {
options.series[0].data = json;
chart = new Highcharts.Chart(options);
});

});

最佳答案

对于点单击事件,您要查找 this.name,因为 this 指的是执行单击的 Point 对象,如 the API 中所定义。 .

在两个格式化程序函数中,this 有一组非常具体的可用数据。它可以访问 this.pointthis.series 等,如 the API 中所定义。 .

参见this JSFiddle demonstration所有三个都在使用中。

关于jquery - HighCharts onclick this.point.name 未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35517379/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com