如何将数组循环到JSON代码中

时间:2016-05-16 18:08:35

标签: javascript

我想将javascript数组循环到json代码中:

{{1}}

我想将我的两个javascript数组循环到这个JSON代码中,但我不知道该怎么做。 我想将我的两个javascript数组循环到这个JSON代码中,但我不知道该怎么做。 我想将我的两个javascript数组循环到这个JSON代码中,但我不知道该怎么做。 谢谢。

1 个答案:

答案 0 :(得分:-1)

在创建对象之前创建一个数组,然后使用该变量。

$(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
        }]
    });
});