0
votes

I Have the following code which generates a basic area chart from JSON data, This work fine on my local host machine http://127.0.0.1, but when i try to view in the web url i get an error

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)

Can anyone help why i am getting this error?

My working code can be seen here in 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
Looks like the json file path is not correct. Where is your file located?Kacper Madej

1 Answers

0
votes

$.getJSON's first arugment is the URL, so I would think it would be

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);
});

Attempting to get data.json from your localhost may have worked because it was a relative path. It would need an absolute path (fully-qualified URL) to the resource. This could also be referenced differently if you're deploying a WAR file as a web-app, which would require <your-web-url>/resources/data1.json or something close to that.