-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
  • 142,114
  • 39
  • 237
  • 299
aZ oTe
  • 21
  • 6

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
  • 669,327
  • 51
  • 454
  • 560