0

I am a beginner in using jQuery Float Chart. Now I try to bind the chat with server side values. I need to build an array structure like below.

data = [{
    label: 'Test 1',
    data: [
        [1325376000000, 1200],
        [1328054400000, 700], 
        [1330560000000, 1000], 
        [1333238400000, 600], 
        [1335830400000, 350]
    ]
},];

My Server Response

enter image description here

My question is how to push items in this array of array. I already try to build an array like this:

    var data = new Array();
    var chartOptions;

$.each(graphdata, function (key, value) {
    data.push({
        label: value.label,
        data: $.each(value.data, function (key, value) {
            Array(value.X, value.Y);
        })
    })
});

Edits

Graph shows in webpage

enter image description here

enter image description here

But it's not working.

1
  • What's not working exactly? Commented Oct 30, 2014 at 8:42

1 Answer 1

1

The problems is that $.each return collection that iterates on - the collection you don't want to. You can use underscore library that contains function map to project value into another:

var postData = [{label:"test1", "data": [ {X: "10", Y:"11"}, {X: "12", Y: "13"}] }];

var data = []

$.each(postData, function (key, value) {
    data.push({
        label: value.label,
        data: _(value.data).map(function(innerVal) {
           var arr = new Array();
           arr.push(innerVal.X);
           arr.push(innerVal.Y);
           return arr;
        })
      })
    });

Here is jsFiddle: click!

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.