I have a unidimensional array filled up with graphic point coordinates that i get from a JSON encoded string, on which i
jsdata = $.parseJSON('[' + strdata + ']');
arr = jsdata[0].toString().split(',');
and i don't seem to quite think up the algorigthm to parse it to a 3 dimensional array, which needs to have the following structure:
data['parameter to plot'][point][coordinate]
As an example, let's say i'm gonna draw a line graph with data from 2 parameters. It will draw 74 points with 2 coordinates for each of the 2 lines which means the array's index will go as far as:
arr[296];
So, the "data" array's indexes will need to go as far as:
data[1][74][1];
I have no problem creating any of the arrays, but developing an algorithm for filling up the "data" array according to "arr's" length is really baking my brain. :/
Thanks for any help bros.
EDIT:
Since i don't know how many parameters i'm gonna need to draw graphs for but i'll know which type of graph i'm going to use, i came up with this answer.
I create a multi dimensional array using this function
function createArray(length) {
var arr = new Array(length || 0),
i = length;
if (arguments.length > 1) {
var args = Array.prototype.slice.call(arguments, 1);
while(i--) arr[i] = createArray.apply(this, args);
}
return arr;
}
And then i can do
function toMulti(arr, plotType)
{
if(plotType =='line_plot')
{
var lineaux = createArray((arr.length/74/2),arr.length/2,2);
var cont = 0;
for(i= 0; i<lineaux.length; i++)
for(j=0; j< lineaux[i].length; j++)
for(k=0; k< lineaux[i][j].length;k++)
{
lineaux[i][j][k] = arr[cont];
cont +=1;
}
return lineaux;
}
}
But a line graph will not always have 74 points, nor will i always plot line graph..
Tell me what you think about it and if you can think up any way to make this non-plotType dependent i'd be eternally grateful. Or just buy you a beer to make it even. :D