in Education by
[Kindly let me know how can I improve this question for your better understanding if I am not clear in describing the situation and what I want] I am changing a chart in my angular app which we built earlier. We are using ng2-charts. Earlier we used TWO JSONs/Arrays. But the REST service (which I can't change as it is coming from a 3rd party service) is changed now. The new REST service looks like below. I tried with one JSON. I am able to see the graph when my input is a hard coded json in the .ts file itself. But I am struggling when I am trying to get the JSON from a REST(GET) call. FYI: I can see the JSON when I print it in the console. Please see the picture I am getting error: Cannot read property 'data' of undefined Below are the two stackblitz examples. The first is with hard coded JSON and second one is from REST call: https://stackblitz.com/edit/ng2-charts-line-template-iq1mia https://stackblitz.com/edit/ng2-charts-line-template-voazjk public summaryboardJson: Summaryboard[]; public lineChartLegend = true; public lineChartType = 'line'; public lineChartPlugins = []; public lineChartOptions: (ChartOptions & { annotation: any }) = { responsive: true, }; public lineChartColors: Color[] = [ { borderColor: 'black', backgroundColor: 'rgba(255,0,0,0.3)', }, ]; public lineChartData: ChartDataSets[]; public lineChartLabels: Label[]; ngOnInit() { this.http .get("https://api.jsonbin.io/b/5c90f7d86892a7259f084846") .toPromise() .then(response => { const data = response.json(); this.summaryboardJson = data; console.log(this.summaryboardJson); //START: put data in Bar Chart this.lineChartData = [ { data: this.summaryboardJson.map(a => a.noOfDefects), label: 'Defects' }, ]; this.lineChartLabels = this.summaryboardJson.map(a => a.Month); //END: put data in Bar Chart }) .catch(error => { console.log(error); return Observable.of([]); }); Any help on this, how to use the JSON from REST call to create the same chart? JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
Try This: https://stackblitz.com/edit/ng2-charts-line-template-umuhe1?file=src%2Fapp%2Fapp.component.ts I have updated your second stackblitz I initialized the lineChartLabels array to a new array and did an ngIf on the length.

Related questions

0 votes
    I want to display an icon when displaying a message from the service message service which uses MatSnackBar. ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 19, 2022 in Education by JackTerrance
0 votes
    I have used angular-cli with systemJS and am now comfortable with its build process,test cases & component ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 3, 2022 in Education by JackTerrance
0 votes
    I have been using a Syncfusion grid in my angular (v.6.0.8) project. In one of the pages, users ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 16, 2022 in Education by JackTerrance
0 votes
    As it currently stands, this question is not a good fit for our Q&A format. We expect answers to ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 23, 2022 in Education by JackTerrance
0 votes
    Which of the following is correct? A.We can use json data directly in axios B.we can use json data directly ... only we can use axios Select the correct answer from above options...
asked Dec 19, 2021 in Education by JackTerrance
+1 vote
    __________ takes in raw data and transforms into charts, graphs and images that can flawlessly explain numbers in a marvelous way to gain insights from it...
asked Oct 11, 2020 in Education by anonymous
0 votes
    Can we use JSON instead of YAML while developing docker-compose file in Docker?...
asked Jun 21, 2021 in Technology by JackTerrance
0 votes
    Can We use comments inside a JSON file? If so, how?...
asked Jan 11, 2021 in Technology by JackTerrance
0 votes
    Complete the charts. Please answer the above question....
asked Aug 20, 2022 in Education by JackTerrance
0 votes
    Complete the following charts: S.No. Column 'A' Column 'B' 1. Joint Naval Exercises ........ 2. Oil imports .... ... . Hydel Power Plant ......... Please answer the above question....
asked Aug 4, 2022 in Education by JackTerrance
0 votes
    Complete the following charts: S.No. Help extended by India Beneficiary Nations 1. Sent Peacekeeping Force to ... produce Hydel Power Bhutan Please answer the above question....
asked Aug 4, 2022 in Education by JackTerrance
0 votes
    Prepare the following flow charts: 1. 2. 3. Please answer the above question....
asked Aug 4, 2022 in Education by JackTerrance
0 votes
    I have the following data-frame: -- dcc.Dropdown for selecting the issue goes here on the page -- ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 26, 2022 in Education by JackTerrance
0 votes
    *Updated with more relevant code. *Updated again: removing chart groupings results in this error: "Unable to ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 1, 2022 in Education by JackTerrance
0 votes
    I'm implementing charts using The Ziya Charts Gem. Unfortunately, the documentation isn't really helpful or ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 23, 2022 in Education by JackTerrance
...