1

我的数据格式如下:

即mymy= UnitedStates,65|UnitedKingdom,58|Germany,30|India,60|Russia,65|China,75

代码 :

            var myarr = mymy.split("|");
            var i=0;
            var myarr2 = [];
            for (i=0;i<myarr.length;i++)
            {
            var mytemp=myarr[i].split(",");
              myarr2[i]=mytemp[0]+','+mytemp[1];
            };
             var myChart = new JSChart('chartcontainer','bar');
             var myData2 = new Array(myarr2);
                   /* 
                   where mow 
                    myarr2[0]={UnitedStates,65}
                    myarr2[1]={UnitedKingdom,58}
                    and so on 

                   */
              myChart.setDataArray(myData2);                
              myChart.draw();
4

1 回答 1

0

看起来 dataArray 必须是一个数据点数组,每个数据点都是一个以标签和值作为成员的数组。所以我想应该是:

var mymy = 'UnitedStates,65|UnitedKingdom,58|Germany,30|India,60|Russia,65|China,75'
var myarr = mymy.split("|");
var myarr2 = [];
for(i=0;i<myarr.length;i++){
    var mytemp=myarr[i].split(",");
    myarr2[i] = [mytemp[0],mytemp[1]];
};
var myChart = new JSChart('chartcontainer','bar');

myChart.setDataArray(myarr2);                
myChart.draw();
于 2013-11-13T05:14:22.473 回答