js的json转换

静态页面是:

 data:[{
                    value:2.5,
                    itemStyle:{
                      normal:{color:'#4a90e2'}    
                    }
                },{
                    value:2.5,
                    itemStyle:{
                      normal:{color:'#4a90e2'}    
                    }
                },{
                    value:2.5,
                    itemStyle:{
                      normal:{color:'#4a90e2'}    
                    }
                },{
                    value:2.5,
                    itemStyle:{
                      normal:{color:'#4a90e2'}    
                    }
                },{
                    value:2.5,
                    itemStyle:{
                      normal:{color:'#4a90e2'}    
                    }
                },{
                    value:2.5,
                    itemStyle:{
                      normal:{color:'#4a90e2'}    
                    }
                },{
                    value:1.5,
                    itemStyle:{
                      normal:{color:'#ec3434'}    
                    }
                },{
                    value:2.5,
                    itemStyle:{
                      normal:{color:'#4a90e2'}    
                    }
                },{
                    value:2.5,
                    itemStyle:{
                      normal:{color:'#4a90e2'}    
                    }
                },{
                    value:2.6,
                    itemStyle:{
                      normal:{color:'#4a90e2'}    
                    }
                },{
                    value:2.6,
                    itemStyle:{
                      normal:{color:'#4a90e2'}    
                    }
                },{
                    value:2.6,
                    itemStyle:{
                      normal:{color:'#4a90e2'}    
                    }
                },{
                    value:2.6,
                    itemStyle:{
                      normal:{color:'#4a90e2'}    
                    }
                },{
                    value:2.6,
                    itemStyle:{
                      normal:{color:'#4a90e2'}    
                    }
                },{
                    value:2.6,
                    itemStyle:{
                      normal:{color:'#4a90e2'}    
                    }
                },{
                    value:2.6,
                    itemStyle:{
                      normal:{color:'#4a90e2'}    
                    }
                },{
                    value:3.0,
                    itemStyle:{
                      normal:{color:'#f2df0b'}    
                    }
                },{
                    value:2.5,
                    itemStyle:{
                      normal:{color:'#4a90e2'}    
                    }
                },{
                    value:2.5,
                    itemStyle:{
                      normal:{color:'#4a90e2'}    
                    }
                },{
                    value:2.5,
                    itemStyle:{
                      normal:{color:'#4a90e2'}    
                    }
                },{
                    value:2.5,
                    itemStyle:{
                      normal:{color:'#4a90e2'}    
                    }
                },{
                    value:2.5,
                    itemStyle:{
                      normal:{color:'#4a90e2'}    
                    }
                },{
                    value:2.5,
                    itemStyle:{
                      normal:{color:'#4a90e2'}    
                    }
                },{
                    value:2.5,
                    itemStyle:{
                      normal:{color:'#4a90e2'}    
                    }
                }]

这不是一维数组,不能在js中

var xTotal = new Array();

可以转换成json即可

//共有多少节电池
        //拼接成X轴
        //拼接成Y轴
        var xTotal = new Array();
        var yTotal = new Array();
        for(var i=0;i<result.data.length;i++){
            xTotal.push((i+1));
            
            var ytemp = "{value:"+result.data[i].bettervol+",itemStyle:{normal:{color:'#4a90e2'}}}";
            
            yTotal.push(eval('(' + ytemp + ')'));         --------------关键点
        }
原文地址:https://www.cnblogs.com/zrui-xyu/p/5543352.html