Highcharts:无法获得示例来显示图表 [英] Highcharts: Cannot get example to display chart

查看:117
本文介绍了Highcharts:无法获得示例来显示图表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法显示下列图表。以下是jQuery。我已经通过替换jQuery尝试了其他示例,并且它可以工作。我将所有文件放在同一个文件夹中,包括data.csv。

  $(document).ready(function(){
var options = {
chart:{
renderTo:'container',
defaultSeriesType:'列'
},
<...更多选项...>
};


$ .get('./ data.csv',function(data){
//拆分行
var lines = data.split('\ n');
$ .each(行,函数(lineNo,line){
var items = line.split(',');

//标题行包含(itemNo> 0)options.xAxis.categories.push(item(itemNo,item)){
if(lineNo == 0){
$ .each );
});
}

//其余的行包含名字在第一位置的数据
else {
var series = {
data:[] $ (itemNo == 0){
series.name = item;
;
$ .each(item,function itemNo,item){
if(itemNo == 0)
} else {
series.data.push(parseFloat(item));
}
});

options.series.push(series);

}

});

var chart = new Highcharts.Chart(options);
});
});

CSV文件如下所示:

 分类,苹果,梨,橘子,香蕉
约翰,8,4,6,5
简,3,4,2,3
Joe, 86,76,79,77
Janet,3,16,13,15

是我尝试工作的示例:



http://www.highcharts.com/studies/data-from-csv.htm

编辑:I只是意识到图表显示在Firefox上。我一直在使用Chrome。很奇怪。但是,上面的示例链接适用于这两种情况。 解决方案

在Chrome中,您不允许使用AJAX获取本地文件。如果你想做这样的事情使用XAMPP或WAMP来创建本地服务器。 Firefox不会有这样的限制。

I cannot get the following chart to display. The following is the jQuery. I've tried other examples by replacing the jQuery and it works. I have all my files in the same folder, including data.csv.

$(document).ready(function () {
    var options = {
        chart: {
            renderTo: 'container',
            defaultSeriesType: 'column'
        },
        < ...more options here... >
    };


    $.get('./data.csv', function (data) {
        // Split the lines
        var lines = data.split('\n');
        $.each(lines, function (lineNo, line) {
            var items = line.split(',');

            // header line containes categories
            if (lineNo == 0) {
                $.each(items, function (itemNo, item) {
                    if (itemNo > 0) options.xAxis.categories.push(item);
                });
            }

            // the rest of the lines contain data with their name in the first position
            else {
                var series = {
                    data: []
                };
                $.each(items, function (itemNo, item) {
                    if (itemNo == 0) {
                        series.name = item;
                    } else {
                        series.data.push(parseFloat(item));
                    }
                });

                options.series.push(series);

            }

        });

        var chart = new Highcharts.Chart(options);
    });
});

The CSV file looks like:

Categories,Apples,Pears,Oranges,Bananas
John,8,4,6,5
Jane,3,4,2,3
Joe,86,76,79,77
Janet,3,16,13,15

Here is the example I am trying to get working:

http://www.highcharts.com/studies/data-from-csv.htm

EDIT: I just realized that the chart displays on Firefox. I have been using Chrome. Very weird. However, the example link above works on both.

解决方案

In Chrome you are not allowed to use AJAX to get local files. If you want do such thing use XAMPP or WAMP to create local server. Firefox doens't have such limits.

这篇关于Highcharts:无法获得示例来显示图表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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