What is difference when we type static content of a multi dynamic array and we create a array of array

StackOverflow https://stackoverflow.com/questions/3770245

  •  04-10-2019
  •  | 
  •  

Question

if i am using below static values than my code is working fine:

ohlc = [[090300, 25.75, 25.75, 25.75, 25.75], 
  [090400, 25.75, 25.75, 25.75, 25.75], 
  [090700, 25.73, 25.73, 25.73, 25.73], 
  [091300, 25.76, 25.76, 25.76, 25.76]];

but if i am using below code than my code is not working

var labels = xmlDoc.getElementsByTagName('node');
        arr = new Array();
        var str = '';
        for (i = 0; i < labels.length; i++) {
            if (labels[i].childNodes.length >= 9) {
                arr[i] = new Array(5);
                arr[i][0] = labels[i].childNodes[1].textContent;
                arr[i][1] = labels[i].childNodes[3].textContent;
                arr[i][2] = labels[i].childNodes[5].textContent;
                arr[i][3] = labels[i].childNodes[7].textContent;
                arr[i][4] = labels[i].childNodes[9].textContent;
            }


        }

even i did loop on arr and alert the value than i have copyed value of array and pasted static and its working.. i am reading xml and creating an 2D array to show chart in jqphot. please give me a clue for this

Was it helpful?

Solution

You probably need to convert the text strings to numbers. You would use the parseFloat function for that:

// ...
arr[i] = new Array(5);
arr[i][0] = parseFloat(labels[i].childNodes[1].textContent);
// ...
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top