Solved

Get two dimensional array prepared to print graph

Posted on 2014-01-08
1
208 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

The Orion Papers

Are you interested in becoming an AWS Certified Solutions Architect?

Discover a new interactive way of training for the exam.

Question has a verified solution.

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

PROBLEM: The other day I was working on adding an ajax request to a webpage that already had a dialog box on the page.  The dialog box was using relative positioning to be positioned next to a form field I had on the page.  Everything was working…
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
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)
Suggested Courses

627 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