2

Possible Duplicate:
HighCharts uncaught exception

I'm trying to instantiate a highcharts objects with this code:

$(function () {
    var chart;
    var json = null;
    $.getJSON('{%  url ajax_search 'pie_chart'  %}?{{request.META.QUERY_STRING}}',
             function(data, textStatus, jqXHR)
            {
                json = data.template;
                            console.log(json);
                chart = new Highcharts.Chart(json);
            });
})

The console logs the returned json appropriately.

When I copy and past in the json to where the (json) is, the chart renders. However, as it is now, it throws the following error: Uncaught Highcharts error #13: www.highcharts.com/errors/13

Following that link it says:

This error occurs if the chart.renderTo option is misconfugured so that Highcharts is unable to find the HTML element to render the chart in

However, again, if I copy and past the json (from the console) to where the variable would otherwise be, it works fine.

I'm sure this is something simple. What am I doing wrong here?

4

1 回答 1

3

您尝试将图表呈现到的元素/div 丢失,您可以分享json在控制台中打印的元素/div 吗?另外,如果您可以添加以下更多日志,以便我们更好地了解图片。

我用来解决 highcharts 错误 #13 的一组标准日志是

        console.log("JSON: " + JSON.stringify(chartingOptions));
        console.log("Render to element with ID : " + chartingOptions.chart.renderTo);
        console.log("Number of matching dom elements : " + $("#" + chartingOptions.chart.renderTo).length);

这些应该在调用 Highcharts 构造函数之前添加

        chart = new Highcharts.Chart(chartingOptions);

如果一切顺利,您应该会看到正确的元素 ID,长度为 1。

排查 highcharts 错误 #13 | Highchart & Highstock @ jsFiddle

这是上面演示的日志

JSON: {"chart":{"renderTo":"container"...}}
渲染到具有 ID 的元素:容器
匹配 dom 元素的数量:1

于 2012-10-29T09:19:17.343 回答