jQuery 在 ajax 调用上实例化 highchart 时出现 Highcharts 错误 #13
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13112652/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Highcharts error #13 while instantiating highchart on ajax call
提问by James R
Possible Duplicate:
HighCharts uncaught exception
可能重复:
HighCharts 未捕获异常
I'm trying to instantiate a highcharts objects with this code:
我正在尝试使用以下代码实例化一个 highcharts 对象:
$(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.
控制台适当地记录返回的 json。
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
当我在 json 中复制并传递到 (json) 所在的位置时,图表会呈现。但是,就像现在一样,它会引发以下错误:未捕获的 Highcharts 错误 #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
如果 chart.renderTo 选项配置错误导致 Highcharts 无法找到 HTML 元素来呈现图表,则会发生此错误
However, again, if I copy and past the json (from the console) to where the variable would otherwise be, it works fine.
但是,再一次,如果我将 json(从控制台)复制并传递到变量所在的位置,它就可以正常工作。
I'm sure this is something simple. What am I doing wrong here?
我相信这很简单。我在这里做错了什么?
回答by Jugal Thakkar
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.
您尝试将图表渲染到的元素/div 丢失,您可以分享json
在控制台中打印的内容吗?另外,如果您可以添加以下更多日志,让我们更好地了解图片。
A standard set of logs that I would use to troubleshoot highcharts error #13 are
我用来解决 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);
These should be added just before calling the Highcharts constructor
这些应该在调用 Highcharts 构造函数之前添加
chart = new Highcharts.Chart(chartingOptions);
If all is well you should see the correct element ID, and length as 1.
如果一切顺利,您应该会看到正确的元素 ID,长度为 1。
Troubleshooting highcharts error # 13 | Highchart & Highstock @ jsFiddle
故障排除 highcharts 错误 # 13 | Highchart & Highstock @ jsFiddle
Here is the log that is seen for the demo above
这是上面演示中看到的日志
JSON: {"chart":{"renderTo":"container"...}}
Render to element with ID : container
Number of matching dom elements : 1
JSON: {"chart":{"renderTo":"container"...}}
渲染到元素 ID 为:container
匹配的 dom 元素数:1