Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Get two dimensional array prepared to print graph

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

Industry Leaders: 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

Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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

877 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