Question

I'm trying to draw a chart with data provided in a Spreadsheet, my first problem is with the JSON feed.

  1. If I put the key in the google Json sample it gives me nothing. However I can see clearly the JSON feed if I paste the address in the browser.

  2. Then I insert it in one of the examples from the Highcharts page and it doesn't load.

Fiddle Demo.

$(function() {

    $.getJSON('https://spreadsheets.google.com/feeds/list/1zgfoS-vYXU_SKDyYEa2fUh6zIaluynibs75a2zZIclI/od6/public/values?alt=json-in-script&callback=?', function(data) 
    {   
        // Add a null value for the end date 
        data = [].concat(data, [[Date.UTC(2015, 9, 14, 19, 59), null, null, null, null]]);

        // create the chart
        $('#container').highcharts('StockChart', {
            chart : {
                type: 'spline',
                zoomType: 'x'
            },

            navigator : {
                adaptToUpdatedData: false,
                series : {
                    data : data
                }
            },

            scrollbar: {
                liveRedraw: false
            },

            title: {
                text: 'AAPL history by the minute from 1998 to 2011'
            },

            subtitle: {
                text: 'Displaying 1.7 million data points in Highcharts Stock by async server loading'
            },

            rangeSelector : {
                buttons: [{
                    type: 'hour',
                    count: 1,
                    text: '1h'
                }, {
                    type: 'day',
                    count: 1,
                    text: '1d'
                }, {
                    type: 'month',
                    count: 1,
                    text: '1m'
                }, {
                    type: 'year',
                    count: 1,
                    text: '1y'
                }, {
                    type: 'all',
                    text: 'All'
                }],
                inputEnabled: false, // it supports only days
                selected : 4 // all
            },

            xAxis : {
                events : {
                    afterSetExtremes : afterSetExtremes
                },
                minRange: 3600 * 1000 // one hour
            },

            series : [{
                data : data,
                dataGrouping: {
                    enabled: false
                }
            }]
        });
    });
});

/** * Load new data depending on the selected min and max */

function afterSetExtremes(e) {

    var currentExtremes = this.getExtremes(),
        range = e.max - e.min,
        chart = $('#container').highcharts();

    chart.showLoading('Loading data from server...');
    $.getJSON('https://spreadsheets.google.com/feeds/list/1zgfoS-vYXU_SKDyYEa2fUh6zIaluynibs75a2zZIclI/od6/public/values?alt=json-in-script&callback=?', function(data) 
    {
        chart.series[0].setData(data);
        chart.hideLoading();
    });
}

Can someone point me whats the problem or provide an alternative?

Était-ce utile?

La solution

You need to refer correct values form your spreadsheet, because in that way you have strange object. I advice to parse this json to achieve array, [x,y] or return only y values to data.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top