Issue with assigning Type (Date|number)[][] to Array<,Array<,string|number>> in Angular with typescript and google charts

Currently, I am utilizing Angular 8 along with the Google Charts module.

My latest endeavor involved creating a Google Calendar Chart to complement some existing Google charts within my project.

However, upon passing the data in my component.html file, I encountered an error indicated by my IDE, stating that

Type (Date|number)[][] is not assignable to type Array<Array<string|number>>
. Even though I believed I was correctly passing a 2D array of Dates and Values as required.

Despite successfully compiling on the front-end, when navigating to the page containing the Google calendar, it crashes or becomes unresponsive.

The code snippet from my something.component.html:

<google-chart
            [type]="Calendar"
            [data]="calendarChartData"  <----------------------- HERE IS THE ERROR
            [columnNames]="calendarChartColumnNames"
            [options]="calendarChartOptions">
</google-chart>

The corresponding section in my something.component.ts:

calendarChartOptions = {
    title: 'Some title',
    height: 350,
    calendar: {
      dayOfWeekLabel: {
        fontName: 'Times-Roman',
        fontSize: 12,
        color: '#1a8763',
        bold: true,
        italic: true,
      },
      dayOfWeekRightSpace: 10,
      cellSize: 10,
    }
  };
  calendarChartColumnNames = ['Date', 'someNumber'];
  calendarChartData = [
    [new Date(2019, 3, 13), 333],
    [new Date(2019, 9, 16), 372],
    [new Date(2019, 9, 17), 5333],
    [new Date(2019, 9, 18), 3702],
    [new Date(2019, 9, 19), 3103],
    [new Date(2019, 9, 20), 2244],
    [new Date(2019, 9, 21), 9531],
    [new Date(2019, 9, 22), 5503]
  ];

Lastly, within my something.module.ts:

...
import { GoogleChartsModule } from 'angular-google-charts';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
...

Answer №1

I haven't had the opportunity to work with Google Charts yet...

Based on the error message, it seems like all you have to do is change your dates to strings...

...
calendarChartData = [
    [new Date(2019, 3, 13).toISOString(), 333],
    [new Date(2019, 3, 13).toDateString(), 333], // I'm not entirely sure about the exact format required by the module.
    ...
  ];

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

What is the best way to invoke a function using a string as its name?

In my grid configuration function, I am assigning column definitions. One key, valueGetter, requires a function to be called to fetch the column value. The issue I am encountering is that the API returns this value as a string. When I try to set it using ...

unable to transform this string into an object

https://i.sstatic.net/O46IL.pngWhy am I encountering difficulties converting this string into an object? Any assistance on resolving this error would be greatly appreciated. onSignup(data:any){ localStorage.setItem('users',JSON.string ...

Transmit data via XMLHttpRequest in smaller portions or through a ReadableStream to minimize memory consumption when handling large datasets

Recently, I've been experimenting with JS's XMLHttpRequest Class for handling file uploads. Initially, I attempted to upload files using the following code: const file = thisFunctionReturnsAFileObject(); const request = new XMLHttpRequest(); req ...

ng-bootstrap component 404 error on final angular2 release

angular2 final release. ng-bootstrap alpha v.5 bootstrap components are functioning on html, however when attempting to import them like this import {ViewChild} from "@angular/core/src/metadata/di"; import {NgbDropdown} from "@ng-bootstrap/ng-bootstrap/d ...

Node Sass was unable to locate a binding for the current environment you are using: OS X 64-bit running Node.js 12.x

Currently, I am encountering an issue while constructing an Angular project. The error message that I am facing is as follows: ERROR in Module build failed (from ./node_modules/sass-loader/lib/loader.js): Error: Missing binding /XXXXXXX/node_modules/nod ...

Site breaks down post transition to Angular Universal (SSR)

Apologies in advance for the ambiguous title, I didn't want to make it too lengthy. So here's my issue: I have a confirmation page that appears after the user completes a payment on a third-party gateway (like PayPal). The page redirects back to ...

What is the best way to incorporate Ekko Lightbox into an Angular 7 Project?

I'm facing an issue while implementing Ekko lightbox in my angular project. Specifically, I want to use it in a certain component but I am unsure about how to import the necessary files into that component. After installing Ekko via NPM, I found all ...

Encountering a Problem with Angular 2 Directive *ng-for

Recently started experimenting with the beta version of Angular 2.0 and encountered an error stating "angular is not defined" while trying to add directive: [angular.ngFor]. If you want to take a look, here is the Plunker URL: http://plnkr.co/edit/ULHddLR ...

Cross-origin resource sharing (CORS) seems to be creating a barrier for the communication between my Angular

During the process of developing an Angular and NestJS app with NGXS for state management, I encountered a CORS error while serving my application. The error message in the console indicated: Access to XMLHttpRequest at 'localhost:333/api/product-i ...

Implementing Express.js allows for the seamless casting of interfaces by the body within the request

I have created a similar structure to ASP.NET MVC and uploaded it on my github repository (express-mvc). Everything seems fine, but I am facing an issue with casting the body inside the request object to match any interface. This is what I am aiming for: ...

Toggle the visibility of an input field based on a checkbox's onchange event

I am facing a challenge where I need to display or hide an Input/Text field based on the state of a Checkbox. When the Checkbox is checked, I want to show the TextField, and when it is unchecked, I want to hide it. Below is the code snippet for this compon ...

Transform a 3D text rotation JavaScript file into an Angular component tailored TypeScript file

I have a javascript file that rotates text in 3D format, and I need help converting it into an Angular component specific TypeScript file. You can find the codepen for the original JavaScript code here. Below are my Angular files: index.html <!doctyp ...

When the observable is subscribed to, the data is not immediately available

I am encountering an issue with syncing data from an observable in a service with a component that consumes the data. The data service makes a call to an api service upon creation to gather a list of devices from a server. It seems like this process is fun ...

Ways to display JSON data in Angular 2

My goal is to display a list of JSON data, but I keep encountering an error message ERROR TypeError: Cannot read property 'title' of undefined. Interestingly, the console log shows that the JSON data is being printed. mydata.service.ts import { ...

Empty nested Map in POST request

I am currently working on a springboot application with a React/Typescript frontend. I have defined two interfaces and created an object based on these interfaces. export interface Order { customer_id: number; date: Date; total: number; sp ...

Issue NG8002: Unable to associate 'dataSource' as it is not recognized as a valid attribute of 'table' within MatDialog in Angular 9

After: Date: 2020-03-27T14:07:28.332Z - Hash: 1e8f94aad69b7bd33179 5 unchanged chunks chunk {main} main.js, main.js.map (main) 205 kB [initial] [rendered] Time: 1532ms : Compiled successfully. Failed to compile. src/app/components/dialog.html:76:20 - er ...

Can you show me the steps for linking the next method of an EventEmitter?

After emitting an event, I am looking to run some additional code. Is there a method to chain the .next() function in this way? @Output() myEvent = new EventEmitter<string>(); this.myEvent.next({‘test string’}).onComplete(console.log('done& ...

Encountering an emscripten error when using MediaInfo.js with Angular 16

Trying to integrate mediainfo.js with Angular 16 based on the documentation found at https://github.com/buzz/mediainfo.js. Following the documentation, we have installed the necessary dependencies : Installation : "@types/emscripten": "^1. ...

Warning message regarding unhandled promise rejection in NestJS websockets

I've encountered a puzzling issue while attempting to integrate an 'events' module into my application to utilize websockets. Upon adding the module, an unexpected error surfaced: (node:59905) UnhandledPromiseRejectionWarning: Unhandled pro ...

The default value for the ReturnType<typeof setInterval> in both the browser and node environments

I have a question about setting the initial value for the intervalTimer in an Interval that I need to save. The type is ReturnType<typeof setInterval>. interface Data { intervalTimer: ReturnType<typeof setInterval> } var data : Data = { ...