这是我的数据..
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? 提前谢谢......
答案 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>