我正在尝试将高图事件作为JSON属性传递,这样当我单击该栏时它会导航到指定的URL,但是我得到了上述错误。这是我在jsfiddle上运行的代码。所有的高图属性都是从JSON文件中读取的。
$(function () {
$(document).ready(function () {
var chart;
var container = "summary";
var data_1 = [24,2];
var title = "Plant Summary";
var subtitle = "";
var data_1url = 'http://www.google.com';
chart = new Highcharts.Chart({
"subtitle": {
"text": subtitle,
"align": "left",
"enabled": false,
"style": {
"color": "#ffffff",
"font-size": "12px",
"font-family": "Segoe UI Light"
},
"x": 0
},
"yAxis": {
"title": {
"text": ""
},
"plotLines": [{
"color": "#808080",
"width": 1,
"value": 0
}]
},
"series": [{
"color": "#d5d5d5",
"url": data_1url,
"data": data_1,
"name": "Level 1"
}],
"title": {
"text": title,
"align": "center",
"enabled": false,
"style": {
"color": "#ffffff",
"font-size": "14px",
"font-family": "Segoe UI Light"
},
"x": ""
},
"chart": {
"zoomType": "xy",
"marginBottom": 50,
"height": 170,
"animation": "true",
"backgroundColor": "transparent",
"marginRight": 20,
"renderTo": container,
"type": "bar"
},
"plotOptions": {
"series": {
"stacking": "percent",
"cursor": "pointer",
"point": {
"events": {
"click": "function() {location.href = this.options.url);"
}
}
}
},
"xAxis": {
},
"exporting": {
"enabled": false
},
"legend": {
"verticalAlign": "bottom",
"align": "center",
"enabled": false,
"borderWidth": 0,
"y": 0,
"x": 0,
"layout": "horizontal"
}
});
});
});
答案 0 :(得分:1)
这是语法错误,您需要使用}
代替)
:
"function() {location.href = this.options.url);"
---------------------------------------------^
使用}
关闭它。
此外,您不会将function()
括在"
内。所以最终的代码是:
"events": {
"click": function() {location.href = this.options.url;}
}
答案 1 :(得分:0)
问题在于在JSON中传递函数,可能的解决方案是将( function() {} )
添加到您的代码中,然后评估这些值:http://jsfiddle.net/g5MHF/2/
此外,根据您的数据,您应该this.series.options.url
(您的系列有网址,而非点数)。