后台返回的数据 result.data = ['2005',2]-['2006',1]-['2007',3]-['2008',6] ,然后
var obj = result.data.split("-");
var myData = new Array();
for (i = 0; i < obj.length; i++)
{
myData[i] = obj[i];
}
var myChart = new JSChart('graph', 'bar');
myChart.setDataArray(myData);
老是弹出窗口说 Input data in wrong format for selected chart type
可是我如果
var myData = new Array();
myData[0] = ['2005', 2];
myData[1] = ['2006', 1];
myData[2] = ['2007', 3];
myData[3] = ['2008', 6];
var myChart = new JSChart('graph', 'bar');
myChart.setDataArray(myData);
这样就对,不是一样的吗???
还有 result.colors = ['#7979DB', '#7952E9', '#792BC8', '#792BA1']
这样myChart.colorizeBars(result.colors);就不对,
myChart.colorizeBars(['#7979DB', '#7952E9', '#792BC8', '#792BA1']);这样就对
这个数据要怎么包装啊
------解决方案--------------------
myData[0] = ['2005', 2];
与
myData[0] = "['2005', 2]";
当然不一样了,['2005', 2]是对象,"['2005', 2]" 是字符串
将字符串转换成对象可以用 eval 方法。
如:
var s="['2005', 2]";
var obj=eval(s);
alert(obj[0]);
你测试这三句就明白了!