Graphics Reference
In-Depth Information
var
matrix= [];
var
row;
matrix.length = size;
for
(i=0; i<size; i++) {
row = matrix[i] = [];
row.length = size;
for
(j=0; j<size; j++) {
row[j] = 0;
}
}
return
matrix;
}
Next, define the function that will create the matrix by calling your
initialization function and populating it with data. Remember to skip
re-imports from the originating country to avoid extra noise in the data.
function
createMatrix(imports, countries) {
var
matrix = initMatrix(countries.length);
var
i;
var
index= {};
for
(i=0; i<countries.length; i++) {
index[countries[i].ISONo] = i;
}
var
row;
var
irow, icol;
// process the data
for
(i=0; i<imports.length; i++) {
row = imports[i];
icol = index[row.Reporter];
irow = index[row.Partner];
// skip re-imports
if
(irow != icol) {
matrix[irow][icol]= Number(row.Value);