首页 文章

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

提问于
浏览
0

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

Failed to load resource: the server responded with a status of 404 (Not Found) https://devb.........../bm2/data1.json Failed to load resource: the server responded with a status of 404 (Not Found)

任何人都可以帮助我为什么会收到此错误?

我的工作代码可以在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>
'+ 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

    $.getJSON 的第一个问题是网址,所以我认为会是这样

    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 或接近该文件 .

相关问题