0

I'm trying to dynamically populate my pieChartColors array, so that in the end my array will look something like this:

public pieChartColors:Array<Color> = [
{
  backgroundColor: '#141C48'
},
{
  backgroundColor: '#FF0000'
},
{
  backgroundColor: '#EFEFEF'
},
...
]

I'm starting with a blank array and have tried a few different ways to get the values added, but none of them are working (my color values are stored without the hash symbol):

public pieChartColors: Array<Color> = [];

public buildPieChart() {
...        
    for (let pie of pieData) {
      // none of these work
      this.pieChartColors.push(backgroundColor: '#'+pie.backgroundColor);
      this.pieChartColors.backgroundColor.push('#'+pie.backgroundColor);
      this.pieChartColors['backgroundColor'].push('#'+pie.backgroundColor);
    }
...
}

BTW, pieData is an object I'm looping through from the database with the backgroundColor values. If I console.log the pie.backgroundColor, the value is available.

1 Answer 1

1

Just do it like in JavaScript:

this.pieChartColors.push({backgroundColor: '#'+pie.backgroundColor});
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.