zasaz zasaz - 5 months ago 7
Javascript Question

How to fill data using an array?

I have this array:

var arrayAUX = [[ 13, 12,5],[ 13, 10,2],[ 13, 5,10],[ 14, 2,5],[ 14, 3,2],[ 15, 1,2]];


Then I fill another array using previous like this:

for(var i=0; i<arrayAUX.length; i++){
arrayGRAPH.push(arrayAUX[i]);


}

What I want is create a bubble graphic using the array, but it not works. This is how I use:

series: [{
data: [
for( var i=0; i<arrayGRAPH.length; i++){
{ x: arrayGRAPH[i][0], y: arrayGRAPH[i][1], z: arrayGRAPH[i][2] }
}


]
}]


But it doesn't work. How can i do this?

Answer

Initialize your data

var arrayAUX = [[ 13, 12,5],[ 13, 10,2],[ 13, 5,10],[ 14, 2,5],[ 14, 3,2],[ 15, 1,2]];
arrayGRAPH = [];
for (var i=0; i<arrayAUX.length; i++){
        arrayGRAPH.push(arrayAUX[i]);
}
var data = [];
 for( var i=0; i<arrayGRAPH.length; i++){
           data.push( { x: arrayGRAPH[i][0], y: arrayGRAPH[i][1], z: arrayGRAPH[i][2] })
        }

and then set it:

series: [{
        data: data
    }]

check this fiddle http://jsfiddle.net/homdn9md/

Comments