无法加载Highcharts的json文件 [英] Unable to load json File for highcharts

查看:217
本文介绍了无法加载Highcharts的json文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用highcharts将图形添加到我的网站.但是,我是json的新手,无法加载文件.

I am trying to use highcharts to add a graph to my site. However, I am a newby to json and I am having trouble loading the file.

以下是代码: http://jsfiddle.net/czNn2/9/

'graph-data-array2.json'包含:

'graph-data-array2.json' contains:

[{
name: 'Asia',
data: [502, 635, 809, 947, 1402, 3634, 5268]
}, {
name: 'Africa',
data: [106, 107, 111, 133, 221, 767, 1766]
}, {
name: 'Europe',
data: [163, 203, 276, 408, 547, 729, 628]
}, {
name: 'America',
data: [18, 31, 54, 156, 339, 818, 1201]
}, {
name: 'Oceania',
data: [2, 2, 2, 6, 13, 30, 46]
}]

当我在自己的网站上运行此命令时,控制台上没有错误,并且图表应为空白的区域.我正在按照第二个答案回答此先前的问题:正在创建100网站的堆叠面积百分比图

When I run this on my site there are no errors on the console and the area where the graph should be is blank. I am following the advice from the 2nd answer to this prior question: Creating 100% stacked area graph for a website

我还尝试了以下格式的json文件:

I also tried a json file formated as:

[
["Price", "Us", "You"],
[0,0.5,0.5],
[1,0.5,0.5],
[2,0.5,0.5]
]

但是它也不起作用.在这种情况下,我在控制台中收到未捕获的Highcharts错误#13"错误

But it did not work either. In this case I get an error in the console "Uncaught Highcharts error #13"

推荐答案

只是为了确保(因为我没有在您的代码中看到它),请将您的图表添加到您的<div id="container-chart" />中.

Just to make sure (since I didn't see it in your code), add your chart to your <div id="container-chart" />.

您可以通过向图表选项添加属性来实现:

You can do this via adding a property to the chart options:

chart: {
        renderTo: container-chart,
        height: 400
    },

来源: http://api.highcharts.com/highcharts#chart.renderTo

或使用jQuery:

$('#container').highcharts({

原来,您不能在要渲染到的div的ID中使用连字符.您的json看起来不错.这是更新的工作提琴: http://jsfiddle.net/czNn2/5

Turns out you can't use a hypen in the id of the div you're rendering to. Your json seems fine. Here is an updated working fiddle: http://jsfiddle.net/czNn2/5

这篇关于无法加载Highcharts的json文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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