Highchart:JSON无法加载资源:服务器响应状态为404(未找到)

时间:2016-03-31 16:36:43

标签: jquery highcharts

我有以下代码从JSON数据生成基本区域图表,这在我的本地主机http://127.0.0.1上正常工作,但是当我尝试在网址中查看时我收到错误

无法加载资源:服务器响应状态为404(未找到) https://devb.........../bm2/data1.json无法加载资源:服务器响应状态为404(未找到)

任何人都可以帮忙解决这个错误的原因吗?

我的工作代码可以在fiddle

中看到
$(document).ready(function() {
    Highcharts.setOptions({
                    lang: {
                        thousandsSep: ','
                    }
                });

var options = {
                chart: {
                    renderTo: 'container',
                    type: 'area',
                    marginRight: 130,
                    marginBottom: 25
                },
                title: {
                    text: 'Deposit Institution',
                    x: -20 //center
                },
                subtitle: {
                    text: '',
                    x: -20
                },
                xAxis: {
                    categories: []
                },
                yAxis: {
                    title: {
                        text: 'Amount'
                    },
                    plotLines: [{
                        value: 0,
                        width: 1,
                        color: '#808080'
                    }]
                },
                tooltip: {
                    formatter: function() {
                            return '<b>'+ this.series.name +'</b><br/>'+
                            this.x +': $'+ this.y;
                    }
                },
                legend: {
                    layout: 'vertical',
                    align: 'right',
                    verticalAlign: 'top',
                    x: -10,
                    y: 100,
                    borderWidth: 0
                },
                series: []
            }

                     $.getJSON("data1.json", function(json) {
                options.xAxis.categories = json[0]['data'];
                options.series[0] = json[1];
                options.series[1] = json[2];
                chart = new Highcharts.Chart(options);
            });


        });

1 个答案:

答案 0 :(得分:0)

$.getJSON的第一个问题是URL,所以我认为它会是

var url = <your web url> + "data1.json"; // assumes that your URL ends with a forward slash
$.getJSON(url, function(json) {
    options.xAxis.categories = json[0]['data'];
    options.series[0] = json[1];
    options.series[1] = json[2];
    chart = new Highcharts.Chart(options);
});

尝试从本地主机获取data.json可能有效,因为它是相对路径。它需要资源的绝对路径(完全限定的URL)。如果您将WAR文件部署为Web应用程序,这可能会以不同的方式引用,这需要<your-web-url>/resources/data1.json或接近该文件。