leveraging JSON data with ng2-charts

[Please let me know if there is a way to improve this question for better clarity on the situation and what I am seeking]

I am currently working on updating a chart in my Angular application that was previously built using ng2-charts. Initially, we utilized TWO JSONs/Arrays for data. However, the REST service (which is sourced from a third-party provider and cannot be altered) has undergone changes. The new structure of the REST service is as follows. I attempted to work with a single JSON, and I managed to display the graph successfully when using a hardcoded JSON directly in the .ts file.

However, I encountered difficulties when attempting to retrieve the JSON via a REST(GET) call.

As an FYI, I can view the JSON output in the console. Please refer to the image for further details.

I am encountering the following error:

Cannot read property 'data' of undefined

Here are two StackBlitz examples - one with hardcoded JSON and the other using a 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<Summaryboard[]>([]);
            });

If anyone can provide insight on how to effectively utilize the JSON obtained from a REST call to generate the same chart, it would be greatly appreciated.

https://i.sstatic.net/gW1Fh.png

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Can you explain the significance of open={Boolean(anchor)} in a Material-UI component?

Currently dealing with some existing code that includes a MUI menu defined within a React component written using TypeScript: interface Props { anchor: HTMLButtonElement | null; } ... <Menu id="order-menu" anchorEl={anchor} open={Boolean ...

The juvenile entity does not align with the foundational entity [typescript]

After setting "strict": true in my tsconfig.json, I encountered compiler errors when attempting to run the code. To replicate and explore this issue further, you can try running the following code snippet. The problem arises when the child clas ...

Encrypt with AES in TypeScript and decrypt in Go programming language

Looking for assistance with encrypting data in TypeScript and then decrypting it in Go. The issue I'm facing is that the output in Go does not match the input in TypeScript. What could be causing this discrepancy? Below is my TypeScript code: import ...

Using D3-GraphViz in Javascript along with an Angular template: A step-by-step guide

I am attempting to integrate d3-graphviz following the guidance provided here within an angular template, like in this example. The tutorial on the d3-graphviz website advises me to include the following code in the index.html file: <!DOCTYPE html> & ...

Retrieving the true value of semicolon as well as array elements from a URL in Angular

ngOnInit() { const id$ = this.route.paramMap.pipe(map((params) => params.get('id') || 0), map(n => Number(n))); id$.subscribe(id => { this.activeId = id; console.log("ActiveId",this.activeId); ...

Using JavaScript, align an image's coordinates with a specific coordinate within its parent container

I am looking to change the position of my relative image dynamically so that it aligns with a fixed pointer's coordinate that is absolute to it ...

Is there a way to apply a css class to all nested elements in Angular 6 using Ngx Bootstrap?

I've defined a CSS class as follows: .panel-mobile-navs > ul > li { width:100% } Within the HTML, I am utilizing Ngx-bootstrap for a series of tabs like this: <tabset class="panel-mobile-navs" > ... </tabset> My intention is to ...

Issue with ReactJS Typescript: Cannot assign type 'number' to type '0, 8, 16, 24, 32, 40, or undefined'

I am looking to implement a grid from material-ui in react using typescript. You can view the live demo here. I have made adjustments to the example to make it work with typescript. Here is how my demo.jsx file looks like: import { withStyles } from &apo ...

Retrieving information from a Kendo grid cell

I am working on a web application that utilizes Kendo Grid. How can I retrieve the values of the "Ticket No" from the selected checkboxes? https://i.stack.imgur.com/aPOje.png This is my code: var grid = $("#poGrid").data("kendoGrid"); grid.items().filte ...

Ways to deactivate form controls while retaining their values

I need to disable a control in my reactive form while still keeping the value present in the form. The following code successfully disables the control: this.myForm.controls['analysis_horizon'].disable(); However, after disabling, the key " ...

Local environments in Angular do not support file replacement

Within my angular.json file, I have set up configurations for both development and production environments. My goal is to prevent file replacement from occurring when running locally with 'ng serve', but allow it during Docker builds. Is there a ...

Retrieve an array of object values using Angular and TypeScript

I'm attempting to extract the values of objects in an array using a nested for loop. I am receiving JSON data as shown below and have written the following TypeScript code to achieve this. However, I am unable to successfully bind the values to the te ...

Refreshing the status following each integration test - Utilizing Supertest with Nodejs and Typescript

I am currently using supertest to write integration tests for a POST API endpoint: api/v1/students?id="someId". This endpoint should return a 4xx status code if the ID is already in use. import request from "supertest"; import { applyMiddleware, applyRout ...

Testing the automation processes of a React or Node project

I am currently working on a project developed using React, Node.js, and MongoDB. I am looking to create an automation test that will automatically fill in either the login or register form. If anyone has any ideas or suggestions, please share them with m ...

Utilize nodemailer in Angular 6 to effortlessly send emails

I am currently experiencing an issue with my email service form in my Angular 6 application integrated with Node.js. I have set up the form using Bootstrap and Nodemailer for sending emails, but it seems to not be working as expected. Whenever I attempt to ...

Guide to utilizing element reference with material UI components in Angular

I am facing difficulty in accessing the reference of an element. My intention is to wrap the material UI elements within a div and set the opacity: 0 so that it remains hidden in the HTML, allowing me to handle the value in my component.ts file. The main g ...

Required file missing in React application unable to locate

I have a project organized in the following way: - my-app - src - some files - public - index.html - ... When I run npm start, the application functions as expected. Now, I am looking to rename src to application! After renami ...

Sending information to ng-template in Angular6

I'm new to Angular 6 and I have a query. How can I pass data to an ng-template from ngFor? component.html <tr *ngFor="let user of data"> <td>{{user.id}}</td> <td>{{user.username}}</td> <td>{{user ...

Is it possible to omit the expression of <T> when it is not necessary to define?

Is there a way to write code without using the <T> notation when it's not necessary? Here is what I have in mind: interface Props<?T> { className: string data?: T } const props: Props = {className: "hello, world"} const pro ...

Tips for adjusting the dimensions of a child element to match its parent in Angular 12 with Typescript

I have included the child component in the parent component and I am displaying that child component within a col-md-8. What I want to achieve is to highlight a specific div in the child component with additional text, making it equal in size to the parent ...