将javascript数组传递给jqplot图表

时间:2013-06-13 07:13:02

标签: javascript arrays jqplot

这是我的数据..

var rname=new Array();
rname.push('India');
rname.push('Pakistan');
rname.push('Australia');
rname.push('America');
rname.push('Sri Lanka');

var rnqi=new Array();
rnqi.push(4);
rnqi.push(6);
rnqi.push(50);
rnqi.push(40);
rnqi.push(5);

当我使用像

这样的硬编码时
var line1=[['India',4], ['Pakistan',6], ['Australia',50], ['America',40], ['Sri Lanka',5]]

Jqchart工作正常,但我想发送数组数据(rname和rqi).. 有没有办法动态地将javascript数组数据发送到jqplot? 提前谢谢......

1 个答案:

答案 0 :(得分:2)

试试这个

    <script type="text/javascript">
    var rname = new Array();
    rname.push('India');
    rname.push('Pakistan');
    rname.push('Australia');
    rname.push('America');
    rname.push('Sri Lanka');

    var rnqi = new Array();
    rnqi.push(4);
    rnqi.push(6);
    rnqi.push(50);
    rnqi.push(40);
    rnqi.push(5);

    var result = new Array();
    for (var i = 0, j = 0; i < rname.length, j < rnqi.length; i++, j++) {
        var temp = new Array();
        temp.push(rname[i].toString());
        temp.push(parseInt(rnqi[j]));
        result.push(temp);
    }
    var line1 = [['India', 4], ['Pakistan', 6], ['Australia', 50], ['America', 40], ['Sri Lanka', 5]]
    //now result array is similar to line1
</script>