0

I have the following code:

var optionsChart = {
    data: [{
        type: "bla",
        dataPoints: [{
            x: 1,
            y: 3
        }, {
            x: 1,
            y: 2
        }, {
            x: 3,
            y: 4
        }]
    },
    etc...
}

Now I tried to generate the Datas in the dataPoints field dynamically. I have an Array like this:

dataArray = [[1,3], [1,2],[3,4]];

I try to insert his after dataPoints, but when doing this it needs to be exactly like in the code above, but I don't know how to do that.

Any suggestions here? Thank you very much!

0

2 Answers 2

4

You need to do this way:

optionsChart.data[0].dataPoints.push(dataArray.map(function (obj) {
    return {
        x: obj[0],
        y: obj[1]
    };
}));

Or try this way:

optionsChart.data[0].dataPoints = dataArray.map(function (obj) {
    return {
        x: obj[0],
        y: obj[1]
    };
});
Sign up to request clarification or add additional context in comments.

Comments

2

Here you go :

optionsChart.data[0].dataPoints.push(dataArray.map(function(t) {
         return {x: t[0], y: t[1]};
}));

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.