Solved

Get two dimensional array prepared to print graph

Posted on 2014-01-08
1
196 Views
Last Modified: 2014-02-18
I have a two dimensional array:  values[serieNumber][xPosition].
I want to be able to print it as a time series graph and therfore need to extract the different series from values. I need to have each series in this kind of format:

 serie1 = [[0, 0.9], [0.5, 0.87], [1, 0.80],[1.5, 0.75],[2, 0.6],[2.5, 0.57],[3, 0.5],[3.5, 0.4],[4, 0.15],[4.5, 0.2],[9,2, 0.0]];

How do I do that in a loop?

I assume the first value in each pair comes from the 'xPosition'.
0
Comment
Question by:mdoland
1 Comment
 
LVL 43

Accepted Solution

by:
Rob earned 500 total points
ID: 39766729
It would look something like this but hard to know exactly without seeing sample data for your values array

demo: http://jsbin.com/OJOguli/1/edit?js,console
var values = [[[0,0],[1,1],[2,2],[3,3],[4,4],[5,5]],[[3,6],[2,3],[1,8],[0,5],[4,1],[5,8]]];

var series = [];

for (var i=0; i<values.length; i++) {
  series[i] = [];
  for (var xPos in values[i]) {
    series[i].push([xPos, values[i][xPos]]);
  }  
}

console.log(series);

Open in new window

0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
How to build a simple, quick and effective accordion menu using just 15 lines of jQuery and 2 css classes
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question