Angular 2 Google Chart: Defining column type using TypeScript

I am currently attempting to implement the Timeline chart functionality from the angular2-google-chart module for Google Charts. Unlike the other examples provided, this specific chart type requires a column type definition — a requirement not present in the existing samples. Most of the available resources demonstrate setting the type directly in JavaScript, leaving me puzzled on how to specify the column type in TypeScript.

The error message I encounter is: "Invalid data table format: column #1 must be of type 'string'."

You can access the JavaScript example page here: https://developers.google.com/chart/interactive/docs/gallery/timeline

dataTable.addColumn({ type: 'string', id: 'President' });
        dataTable.addColumn({ type: 'date', id: 'Start' });
        dataTable.addColumn({ type: 'date', id: 'End' });
        dataTable.addRows([
          [ 'Washington', new Date(1789, 3, 30), new Date(1797, 2, 4) ],
          [ 'Adams',      new Date(1797, 2, 4),  new Date(1801, 2, 4) ],
          [ 'Jefferson',  new Date(1801, 2, 4),  new Date(1809, 2, 4) ]]);

All the angular2-google-chart examples utilize data structured like this:

public candle_ChartData = [
        ['Day', 'Low', 'Opening value', 'Closing value', 'High'],
        ['Mon', 28, 28, 38, 38],
        ['Tue', 38, 38, 55, 55],
        ['Wed', 55, 55, 77, 77],
        ['Thu', 77, 77, 66, 66],
        ['Fri', 66, 66, 22, 22]
    ];

What I am seeking is a method to explicitly define that 'Day' should have a 'type: string, id: Day' specification.

It seems that this functionality may not be supported, prompting potential modification of the supplied directive to incorporate the necessary column input. Nonetheless, it would be preferable to avoid such adjustments unless absolutely necessary.

https://github.com/vimalavinisha/angular2-google-chart/blob/master/directives/angular2-google-chart.directive.ts

Answer №1

After a bit of searching, I finally stumbled upon the solution to my question. It turns out, the answer was right there in the documentation all along.

https://developers.google.com/chart/interactive/docs/datatables_dataviews

Below is the necessary format:

const chartData = [
    [ {label: 'President', id: 'President', type: 'string'}, 
      {label: 'Start', id: 'Start', type: 'date'},
      {label: 'End', id: 'End', type: 'date'}  ],
        [ 'Washington', new Date(1789, 3, 29), new Date(1797, 2, 3) ],
        [ 'Adams',      new Date(1797, 2, 3),  new Date(1801, 2, 3) ],
        [ 'Jefferson',  new Date(1801, 2, 3),  new Date(1809, 2, 3) ]
  ];

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

How can Angular components that are not directly related subscribe to and receive changes using a declarative approach?

Here's the issue at hand: I'm facing a problem with my Dashboard component. The Dashboard consists of a Sidebar and Navbar as child components. On the Sidebar, I have applied a custom permission directive to the links to determine if the user ha ...

creating interactive tabs in angular using dynamic json values

Currently I am working on a material tab feature where I aim to dynamically generate tabs based on the values from my JSON data. Below is the JSON data: [ { "regionName": "EMEA", "regionCurrency": "USD", "organizationName": "XYZ", "orga ...

A guide to incorporating border radius to images within a composite image with sharp.js in Node.js

In my Node.js project, I am using the sharp library to combine a collection of images into a single image. Although I have successfully created the composite image, I now need to add a border radius to each of the images in the grid. Here is the code snip ...

Deploy the dist folder generated by ng build with the help of msdeploy

Has anyone successfully used msdeploy to install the output of ng build --prod (the dist folder) into IIS? I attempted to do so with this command: msdeploy.exe -verb:sync -source:package=c:\Workspace\MyProject\dist.zip -dest:auto -setPara ...

Difficulty redirecting to a different component after clicking on a Bing Map push pin in Angular

When the Bing Map Push pin is clicked, the Router seems to be undefined in the console log. As a result, I am unable to redirect. However, if I add router.navigate in the constructor, everything works perfectly. Here is my code snippet: import { Comp ...

Determining the sequence of events for @HostListener event within an Angular directive

I am facing an issue with my Angular 9 application wherein a parent component contains a child component (referred to as "overview") which has a button. Upon clicking the button, the child component emits an event that should be handled by the parent compo ...

The Aurelia application encounters a "Maximum call stack size exceeded" error while trying to bind FullCalendar

I am currently working on setting up a JQuery plugin (FullCalendar) within my Aurelia application, which is built using TypeScript. I am relatively new to web development and just trying to get a basic example up and running. To start off, I utilized this ...

Using Type TTextKey to access TOption is not allowed

I'm struggling to understand why there is a complaint about return option[optionTextKey] with the error message: Type TTextKey cannot be used to index type TOption Here's the code snippet causing the issue: type Props< TTextKey, TOpti ...

How can I ensure my function waits for a promise to be resolved using Async / Await?

I'm running into an issue where I want my function to keep executing until the nextPageToken is null. The problem occurs when the function runs for the first time, it waits for the promise to resolve. However, if there is a nextPageToken present in th ...

Cannot upload the same file to both Spring and Angular twice

Having trouble uploading the same file twice. However, it works fine when uploading different files. Encountering an error under the Network tab in Chrome { timeStamp: ......, status: 417 error: 'Bad Request', message: 'Required reques ...

How to successfully extract and understand JSON data in Angular that has been delivered from a Spring controller

I am facing a unique challenge while trying to utilize JSON data obtained from a Spring API to populate a list in Angular. Within the datasets-list.component.ts file, I have the following code: import { Component, OnInit } from '@angular/core'; i ...

Guide on mocking a function inside another function imported from a module with TypeScript and Jest

I have a function inside the action directory that I want to test: import { Action, ActionProgress, ActionStatus, MagicLinkProgress } from '../../interfaces' import { areSameActions } from '../actionsProgress' export const findActionPr ...

Tips for locating the index of a substring within a string with varying line endings using Typescript

I am faced with the task of comparing two strings together. abc\r\ndef c\nde My goal is to determine the index of string 2 within string 1. Using the indexOf() method is not an option due to different line endings, so I require an altern ...

Dynamically loading external JavaScript for an Angular component and triggering the window load event

I am currently dealing with an external javascript file that I only want to be included on a specific component, so the approach I'm taking involves dynamically loading it. I came across this answer that explains exactly how to achieve this. The prob ...

Issue with Typescript express application utilizing express-openid-connect wherein cookies are not being retained, resulting in an infinite loop of redirects

For a while now, I've been facing a block with no resolution in sight for this particular issue. Hopefully, someone out there can lend a hand. Background I have a TS express application running on Firebase functions. Additionally, I utilize a custom ...

Employing Bazel in conjunction with Lerna and Yarn workspaces

It seems that a lot of people are currently utilizing lerna and/or yarn workspace. I'm thinking about either transitioning from them to Bazel, or perhaps integrating them with Bazel in conjunction with an example project for guidance. Take for insta ...

Sending real-time data from the tRPC stream API in OpenAI to the React client

I have been exploring ways to integrate the openai-node package into my Next.js application. Due to the lengthy generation times of OpenAI completions, I am interested in utilizing streaming, which is typically not supported within the package (refer to he ...

The ngFor directive seems to be malfunctioning as it is only displaying a single element from the object instead of iterating through all of them in Angular version 12

I'm having trouble looping through my array of objects in the UI. Only one element is being displayed. Can anyone help me figure out what I'm doing wrong? Here is my component.html file: <div class="card" *ngFor="let regionList ...

GraphQL queries that are strongly-typed

Currently working on a Vue CLI project where I am utilizing axios as my request library. In all the examples I've come across, they use strings for queries like this: { hero { name friends { name } } } Given that I am employing ...

Is there a distinction between Entity[] and array<Entity> in TypeScript?

Everything in the title, for example people: Person[]; people: Array<Person>; What sets them apart? Is there a preferred approach? Note: I couldn't find any guidance on this and I've encountered both in code. ...