[Chartjs]-Calling data from search bar to chart.js graph in Angular

1👍

In home-page component, this.post refers to an array of objects. To generate arrays from array of objects, use map(). Try the following

home-page.component.ts:

let postname = this.post.map(p => p.name);
let postsour = this.post.map(p => p.sour);
let postsweet = this.post.map(p => p.sweet);

Working example: Playground

I’ve created a crude Stackblitz for your code here. Naturally since I didn’t have access to the component templates, I’ve bound the chart generation to a button element. Feel free to modify it to your requirements.

Leave a comment