Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Get two dimensional array prepared to print graph

Posted on 2014-01-08
1
Medium Priority
?
223 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 2000 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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…
This article discusses how to create an extensible mechanism for linked drop downs.
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)
The viewer will learn the basics of jQuery including how to code hide show and toggles. 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…
Suggested Courses

715 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