0

I am currently working on a Box and Whisker Plot project in which the data is from a PHP file and then transferred to javascript function to generate the Box and Whisker Plot. I have here a source on how to generate data but from a random number ranging from 0-15:

 var offset = Math.random()*3/4;
 var data = pv.range(0,15).map(function(i) {
     return offset + Math.random()/4;}).sort();

How would I output my JSON converted data to this javascript file? I am thinking to change the var data into:

var data = [[1,2,3,4,5],[2,3,4,5,6],[0,1,2,3,4]]

But this one does not work. How would I do it? Thank you.

2
  • What does JSON have to do with this? It sounds like you are talking about building a javascript array/object literal. What do you mean when you say you want to output the array to a javascript file? Typically javascript files are static content. Commented Mar 12, 2014 at 18:06
  • Your question is not clear. If you're getting data from a php file, why would you set data to the above array? Commented Mar 12, 2014 at 18:06

1 Answer 1

1
    var jsonArr = {
    data:[]
              };
jsonArr.data.push(new Array(1,2,3,4,5));
jsonArr.data.push(new Array(3,4,2,1));
alert(jsonArr);
alert(JSON.stringify(jsonArr));

If you want to convert your javascript object to a json string, use JSON.stringify(yourObject);

Sign up to request clarification or add additional context in comments.

Comments

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.