Jquery将数组添加到数组的末尾而不与现有项

时间:2017-04-03 13:35:16

标签: jquery

ALO,

我正在尝试为Jqplot创建动态数组并运行问题。基本上,我想在jqplot examples中创建类似于示例二的条形图。生成图表的代码是:

    var s1 = [2, 6, 7, 10];
    var s2 = [7, 5, 3, 2];
    var ticks = ['a', 'b', 'c', 'd'];

    plot2 = $.jqplot('chart2', [s1, s2], {
        seriesDefaults: {
            renderer:$.jqplot.BarRenderer,
            pointLabels: { show: true }
        },
        axes: {
            xaxis: {
                renderer: $.jqplot.CategoryAxisRenderer,
                ticks: ticks
            }
        }
    });

我的图表将基于表格。我想用自己的系列数组替换系列数组[S1,S2],但到目前为止失败了。问题是结果是单个阵列1,2,3,4。这是我的代码,它从表的第1列然后从第2列获取数据。我希望column1为s1,column2为s2。但是,根据需要,我可能需要更多列,所以我有兴趣让它尽可能动态。现在的问题是我最终获得1,2,3 ....所有列都混合了。还有一个.each可以获取哪个列索引。它工作正常。

var chartData=[]; // to store S1,S2,S3 etc
var columnData=[]; //to store one set of array such as S1.
    $('#tblhighlight thead tr th.dbgroups ').each(function (index, groupname) {

            var valueColumn=index+2;    //which column to get data from

  $('#tblhighlight tbody tr td:nth-child('+valueColumn+') ').each(function (indexcell, cellvalue) {

columnData.push( parseInt($(cellvalue).html()));

            });

             chartData.push(columnData);

 });

我希望因为columnData是一个数组,所以当它被推送时,它将被推送为数组而不是单个项目。我该如何过去呢?

0 个答案:

没有答案
相关问题