Solved

Get two dimensional array prepared to print graph

Posted on 2014-01-08
1
192 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 42

Accepted Solution

by:
Rob Jurd, EE MVE 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 Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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)

708 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now