0

I'm not sure how I can push data to the "data" property within "decData".

        var decData = {
            labels: [],
            datasets: [

                {
                    fillColor: "rgba(151,187,205,0.5)",
                    strokeColor: "rgba(151,187,205,1)",
                    data: []
                }
            ]
        }

Here is the code I'm using that isn't working

        decData.datasets.data.push(dayProfit);

Could anyone tell me what I'm doing wrong? The error is

Uncaught TypeError: Cannot call method 'push' of undefined

2
  • 4
    Try decData.datasets[0].data.push(dayProfit) since datasets is an array. Commented Feb 5, 2014 at 20:16
  • Wow, how did I miss that. Thanks a bunch mate! Commented Feb 5, 2014 at 20:17

3 Answers 3

1

Your datasets object is an array, so you would need to address an element within the array:

decData.datasets[0].data.push(dayProfit);
Sign up to request clarification or add additional context in comments.

Comments

0

I your code, datasets is an array. Try this:

decData.datasets[0].data.push("stuff");

Good Luck!

Comments

0

You can always add a push method to your object:

var decData = {
        ...
        push: function (value){
            this.datasets[0].data.push(value);
        }
    }

now you can use this method:

decData.push(dayProfit);

But you have have to ask yourself the question, is the first data set the only place you want to push data to? cause this is what the code does.

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.