Sign up ×
Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them, it only takes a minute:

I am trying to make a graph of my own data (JS)which I have stored in a php array

Now I have to make some kind of loop to make(Javascript)

  dataPoints: [

              { x: 10, y: 10 },
              { x: 20, y: 15 },
              { x: 30, y: 25 },
              { x: 40, y: 30 },
              { x: 50, y: 28 }
              ]

Needs to be something like

 {x: $arraytime[0], y:arraycloud[0]) , 
 {x: $arraytime[1], y:arraycloud[1]) , 
 {x: $arraytime[2], y:arraycloud[2]) , 

etcetera.

I have no clue how to do this

share|improve this question

1 Answer 1

up vote 1 down vote accepted

You can use a json_encode for this, if you prepare the array in php, like this:

$arr = array();
for ($i = 0; $i < count($arraytime); $i++) {
    $arr[] = array('x' => $arraytime[$i], 'y' => $arraytime[$i]);
}

echo json_encode($arr);
share|improve this answer
    
This worked. Now I ahve another problem X: 140222 is time and should be displayed as 14:02:22 .. how can i do that? – Rafael van den Berg Nov 12 '14 at 20:52
    
You're going to want to look at PHP's date function: php.net/manual/en/function.date.php – Casey Rule Nov 12 '14 at 20:54
    
Would you mind marking this answer as accepted? – Casey Rule Nov 12 '14 at 20:54
    
Uhm ye sure .. but i need to figure out how to display 140222 as 14:02:22 instead of 140,222 – Rafael van den Berg Nov 12 '14 at 20:59
    
You'll want to use PHP's date function for that. – Casey Rule Nov 12 '14 at 21:01

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.