Unable to transform data into ng2-chart [Bar Chart]

Exploring angular for the first time and currently working with Angular 7. I am in need of converting my api data into the ng2-charts format.

This is a snippet of my api data:

{
    "status": 200,
    "message": "Fetched Successfully",
    "data": [
      {
        "1": [
          {
            "productid": "5c595f1c736429312f1ee15b",
            "totalQty": 5
          },
          {
            "productid": "5c595f1c736429312f1ee158",
            "totalQty": 54
          },
          {
            "productid": "5c595f1c736429312f1ee157",
            "totalQty": 156
          }
        ],
        "2": [
          {
            "productid": "5c595e3b736429312f1ee155",
            "totalQty": 15
          },
          {
            "productid": "5c595f1c736429312f1ee157",
            "totalQty": 42
          }
        ],
        "5": [
          {
            "productid": "5c595e3b736429312f1ee155",
            "totalQty": 50
          },
          {
            "productid": "5c595f1c736429312f1ee157",
            "totalQty": 70
          }
        ],
        "12": [
          {
            "productid": "5c595e3b736429312f1ee145",
            "totalQty": 17
          },
          {
            "productid": "5c595f1c736429312f1ee157",
            "totalQty": 5
          }
        ]
      }
    ]
  }

Below shows the desired output format:

  public barChartLabels = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12']; 
  public barChartType = 'bar';
  public barChartLegend = true;

  public barChartData = [ 
    { data: [5], label: '5c595f1c736429312f1ee15b' },
    { data: [54], label: '5c595f1c736429312f1ee158' },
    { data: [156, 42, , , 70, , , , , , , 5], label: '5c595f1c736429312f1ee157' },
    { data: [, 15, , , 50], label: '5c595e3b736429312f1ee155' },
    { data: [, , , , , , , , , , , 17], label: '5c595e3b736429312f1ee145' },
    { data: [, 15], label: '5c595e3b736429312f1ee145' }
  ];

I aim to create a dynamic chart as more data will be fetched from the api over time.

Attempts at using loops have proven to complicate matters and consume more time, thus exploring more efficient solutions.

Appreciate your assistance in advance

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

I wish to have the sidebar shown initially, then be able to collapse it by clicking a button and adding a dropdown feature to the side of the menu items using Bootstrap

I am looking to implement a sidebar menu using Bootstrap. I want the ability to hide the menu, even on larger screens, by clicking a button. When collapsing the menu to the left side, I want the icons to display on the left as well. Clicking on a menu i ...

Utilizing the Vue feature of dynamic route naming within a component's function

Currently, I am working on creating a dynamic view rendering using Vue and Laravel. However, I am facing difficulty in understanding how to pass the dynamic parameter to the component function. Router.map({ '/cms-admin/:page': { comp ...

The select tag containing the ng-model attribute fails to display the preset default value from the controller

Within the pagination feature, a dropdown menu has been included to allow users to select the number of items displayed on each page. However, there seems to be an issue with the default values that have been set in the controller not displaying correctly. ...

Incapable of stacking one canvas on top of another

I'm new to javascript and looking for help with positioning a canvas element behind another. The code I have may be a bit messy, so any assistance is greatly appreciated. My goal is to have the canvas named "myCanvas" appear behind "coinAnimation". Th ...

The webpage becomes unresponsive due to an Ajax request

Creating a generic way to call ajax requests on my webpage has been challenging. I've developed an extension method for calling post requests asynchronously. $.tiqPost = function(action,data,callback) { alert('Posting...'); $.fancyb ...

Encountered an issue while compiling code using the Istanbul plugin

I'm currently working on generating a code coverage report for my ReactJS project using the babel-istanbul-plugin. However, when I incorporate "istanbul" as a plugin in my .babelrc file and attempt to build, I encounter the following error: ERROR in ...

Implement error handling with the try/catch function when utilizing transaction sessions within the wrapper

Performing multiple database actions within functions can be complex, especially when handling failures. That's why I utilize a transaction session from Mongoose to easily revert any actions if needed. To begin, I initialize a session using the start ...

Guide to developing and showcasing a proof of concept (PoC) for a Google Chrome vulnerability using Out of Bounds (oob) method

While reading through an article discussing the Proof of Concept of a CVE in Google Chrome (OOB issue), I came across this intriguing code snippet: (https://medium.com/@elniak/cve-2024-4761-exploiting-chromes-javascript-engine-highly-exploited-poc-presente ...

Is there a way to determine if a unique value is present in a jQuery array?

$.each(date_range, function(kr, time) { alert('time' + '=>' + time) alert(data_d.indexOf(time) != -1); if (time == timestamp) { data_d.push([timestamp, v.kreditbetrag]); } else { data_d.push([time, 0] ...

Acquire the current audio video stream directly from the web browser

Currently, I am utilizing a JavaScript library that internally invokes getUserMedia. My objective is to access the stream object that has already been initiated. Unfortunately, the library does not provide any means to retrieve it. Is there a method avai ...

What is the best way to send an ID to my ui-view component?

I am trying to access inventory items by their ID using the link /inventory/description/:{{id}}. However, I am facing some issues with it as nothing is showing up. How can I successfully access these items by ID? app.config(function config( $stateProvider ...

What is the best way to utilize a color picker to apply CSS color to a parent element?

When the pencil glyphicon is clicked, a color picker appears. I only want to apply the selected color from the color picker to the list elements that are the grand parent of the pencil glyphicon. Here's a snippet of my Ruby front-end code: <% cat ...

Display the Image Element in Angular only when the image actually exists

In my HTML code, I have two sibling elements - one is an image and the other is a div. I want to display the image element if the image exists, and show the div element if the image doesn't exist. Here's how my elements are structured: <img ...

"Enhance your Vue 3 experience with a stylish Instagram Feed featuring

Struggling to retrieve the most recent Instagram posts from a feed using Vue 3 and Axios due to Instagram's strict-origin-when-cross-origin policy causing constant blocks. All access tokens are properly configured. The Instagram Basic Display API gui ...

Disable the confirmation dialog for PUT and DELETE requests from Backbone to Django API in Firefox

Why is Firefox showing a confirmation box for PUT and DELETE requests sent from Backbone to Django REST API, while no such confirmation is required for POST requests? This webpage is being redirected to a new location. Would you like to resend the form ...

Tips for Keeping a Responsive Image at the Forefront of a Text-Image Layout as You Scroll

I'm currently in the process of creating a website where text appears on the left side with an accompanying image on the right. The challenge I'm encountering is ensuring that as users scroll, the image adjusts dynamically based on the associated ...

Is there a way to create a pixelated render target using THREE JS?

Attempting to set up a basic render target where I render one scene and then use it as a texture over a quad. The demo seems to be pixelated when running, almost like it's rendered on a small screen and stretched across the quad. Below is the code sn ...

An intuitive approach to adding a CheckBox control within a GridView using JavaScript and SPAN elements

Struggling to calculate the total quantity from the gridview for checked row checkboxes? Having trouble accessing the checkbox control in your JavaScript? Below is the code snippet you provided, but it's not returning anything. <table cellspaci ...

Data vanishing in upcoming authentication session in test environment

I have encountered an issue with next auth in my next.js project. During development, the session data is lost if the server refreshes or if I switch to another tab and return to it. This forces me to sign out and then sign back in to restore the session d ...

Error in AWS Lambda: JSON parsing error due to unexpected token 't' at position 6

I'm currently working on a basic lambda function that utilizes a post request to insert data into DynamoDB. However, every time I deploy the lambda function and test it using Postman, I keep encountering a 502 Bad Gateway error. To troubleshoot this ...