0

I have to push dynamic value in data

  lineChartData: ChartDataSets[] = [
    { data: [], label: 'prices are' },
  ];

From my method I am pushing values as:

for(let e of x){
      
      this.lineChartData.push(e.raise)
     
    };

How can I push value in data[]?

2
  • You mean lineChartData[0].data.push(e.raise)? Commented Aug 9, 2020 at 11:34
  • If e.raise contains an object in the form of { data: [], label: string },, it will be pushed to lineChartData as a whole. What is exactly the problem you are solving? Any errors? Commented Aug 9, 2020 at 11:36

2 Answers 2

1

you are having nested array/ so you need to run for loop twice

for eg

myArr = [{data:[]}]

for(let i of myArr){
  i.data.push('a');
}

I am passing string you can pass your object/array

using your example object

lineChartData: ChartDataSets[] = [
    { data: [], label: 'prices are' },
  ];

for(let i of lineChartData){
    i.data.push(yourObject)
 
}
Sign up to request clarification or add additional context in comments.

Comments

0

How can I push value in data[]?

Use

lineChartData[0].data.push(e.raise);

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.