Highcharts错误#13,同时在ajax调用上实例化highchart [英] Highcharts error #13 while instantiating highchart on ajax call

查看:2042
本文介绍了Highcharts错误#13,同时在ajax调用上实例化highchart的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:
HighCharts未捕获异常

我试图用这个实例化一个highcharts对象代码:

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);
            });
})

控制台会适当地记录返回的json。

The console logs the returned json appropriately.

当我复制并过去在(json)所在的json中,图表呈现。但是,现在,它会抛出以下错误:Uncaught Highcharts错误#13:www.highcharts.com/errors/13

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

在该链接之后,它说: / b>

Following that link it says:


如果chart.renderTo选项错误配置,则会出现此错误,因此
表示Highcharts无法找到HTML元素来呈现图表
in

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

但是,如果我将json(从控制台)复制并转移到变量所在的位置是的,它工作正常。

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?

推荐答案

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

The element/div you are trying to render the chart to is missing, can you share the json that is printed in the console? Additionaly, if you can add the following more logs to give us a better understanding of the picture.

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

A standard set of logs that I would use to troubleshoot highcharts error #13 are

        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构造函数之前添加

These should be added just before calling the Highcharts constructor

        chart = new Highcharts.Chart(chartingOptions);

如果一切正常,您应该看到正确的元素ID,长度为1.

If all is well you should see the correct element ID, and length as 1.

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

这是上面演示的日志


JSON:{chart:{renderTo:container...}}

呈现给ID为的元素:container

匹配的dom的数量元素:1

JSON: {"chart":{"renderTo":"container"...}}
Render to element with ID : container
Number of matching dom elements : 1

这篇关于Highcharts错误#13,同时在ajax调用上实例化highchart的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆