0

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

1 Answer 1

1

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);
Sign up to request clarification or add additional context in comments.

6 Comments

This worked. Now I ahve another problem X: 140222 is time and should be displayed as 14:02:22 .. how can i do that?
You're going to want to look at PHP's date function: php.net/manual/en/function.date.php
Uhm ye sure .. but i need to figure out how to display 140222 as 14:02:22 instead of 140,222
You'll want to use PHP's date function for that.
I'm happy to elaborate if you'd like, but can you mark this answer as accepted so the thread isn't left open?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.