0

我正在尝试将 highchart 事件作为 JSON 属性传递,这样当我单击该栏时,它会导航到指定的 url,但出现上述错误。这是
我在 jsfiddle 上运行的代码。所有 highchart 属性都是从 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"
        }
            });
        });
    });
4

2 回答 2

1

这是一个语法错误,您需要使用,}而不是)

"function() {location.href = this.options.url);"
---------------------------------------------^

使用}.

而且,你没有把 s 括function()在里面"。所以最终的代码将是:

"events": {
    "click": function() {location.href = this.options.url;}
}
于 2013-02-12T10:16:01.723 回答
0

问题在于 JSON 中的传递函数,可能的解决方案是添加( function() {} )到您的代码中,然后评估该值:http: //jsfiddle.net/g5MHF/2/

另外,应该有this.series.options.url根据你的数据(你的系列有网址,不是一个点)。

于 2013-02-12T15:32:18.487 回答