-8

i want to loop an javascript array into a json code :

$(function () {
            var i = tabdate.length;
    $('#daily').highcharts({
       chart: {
                type: 'area'
            },
            title: {
                text: 'Statistiques journalières'
            },
            subtitle: {
                text: ''
            },
        xAxis: {
            type: 'datetime',
            dateTimeLabelFormats: { // don't display the dummy year
                month: '%e. %b',
                year: '%b'
            },
            title: {
                text: 'Date'
            }
        },
        yAxis: {
            title: {
                text: 'Snow depth (m)'
            },
            min: 0
        },
        tooltip: {
            headerFormat: '<b>{series.name}</b><br>',
            pointFormat: '{point.x:%e. %b}: {point.y:.2f} m'
        },

        plotOptions: {
            spline: {
                marker: {
                    enabled: true
                }
            }
        },

        series: [{
            name: 'Winter 2013-2014',
            data: [
               HERE
            ]
        }]
    });
});

i want to loop my two javascript array into this JSON code, but i don't know how to do it. i want to loop my two javascript array into this JSON code, but i don't know how to do it. i want to loop my two javascript array into this JSON code, but i don't know how to do it. thanks.

Naftali
  • 144,921
  • 39
  • 244
  • 303
aZ oTe
  • 21
  • 7
  • 3
    Possible duplicate of [Is it valid to define functions in JSON results?](http://stackoverflow.com/questions/2001449/is-it-valid-to-define-functions-in-json-results) – Jeff Puckett May 16 '16 at 18:10
  • You want to populate the `series` value with data from two arrays. Is that correct? What do the input arrays look like? What do you want the result to look like? – apsillers May 16 '16 at 18:17

1 Answers1

-1

Create an array before creating the object, and then use that variable.

$(function () {
    var i = tabdate.length;
    var seriesData = [];
    while (i > 0) {
        seriesData.push([tabdate[i], tabnumber[i]]);
    }
    $('#daily').highcharts({
       chart: {
                type: 'area'
            },
            title: {
                text: 'Statistiques journalières'
            },
            subtitle: {
                text: ''
            },
        xAxis: {
            type: 'datetime',
            dateTimeLabelFormats: { // don't display the dummy year
                month: '%e. %b',
                year: '%b'
            },
            title: {
                text: 'Date'
            }
        },
        yAxis: {
            title: {
                text: 'Snow depth (m)'
            },
            min: 0
        },
        tooltip: {
            headerFormat: '<b>{series.name}</b><br>',
            pointFormat: '{point.x:%e. %b}: {point.y:.2f} m'
        },

        plotOptions: {
            spline: {
                marker: {
                    enabled: true
                }
            }
        },

        series: [{
            name: 'Winter 2013-2014',
            data: seriesData
        }]
    });
});
Barmar
  • 741,623
  • 53
  • 500
  • 612