Using Angular to incorporate HighCharts for a gauge chart

I'm currently working on an Angular project where I need to display a statistic using a gauge chart. The thing is, I'm utilizing the HighCharts library and it's worth mentioning that I've successfully used other types of charts from HighCharts in this same project. However, when I tried to implement the gauge chart, I encountered an error in the browser console and unfortunately, nothing happened!

Here's the error message I received:

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

This is what my comparisons.component.ts looks like:

import { Component, Input, OnInit } from '@angular/core';
import { rotateAnimation } from 'src/app/shared/animations';
import * as HighCharts from 'highcharts';
import { StatisticsService } from '../../service/statistics.service';
import { JobPostComparisonOutputDto } from '../../models/job-post-comparison-output.model';

@Component({
    selector: 'app-comparisons',
    templateUrl: './comparisons.component.html',
    styleUrls: ['./comparisons.component.scss'],
    animations: [rotateAnimation]
})
export class ComparisonsComponent implements OnInit {

    @Input() jobPostId: number;
    comparisonsStatistics: JobPostComparisonOutputDto;

    constructor(
      private statisticsService: StatisticsService
    ) {}

    ngOnInit(): void {
      this.statisticsService.getComparisonsStatistics(this.jobPostId).subscribe((res) => {
        this.comparisonsStatistics = res;
        setTimeout(() => {
          this.generateGaugeChart();
        }, 500);
      });
    }

    generateGaugeChart() {
      this.comparisonsStatistics.listOfJobPostComparisonStatisticsPerRound.forEach(res=>{
        HighCharts.chart('gaugeChart_' + res.roundNumber, {
          chart: {
            type: 'gauge',
            plotBackgroundColor: null,
            plotBackgroundImage: null,
            plotBorderWidth: 0,
            plotShadow: false,
            height: '80%'
          },
          title: {
            text: 'Speedometer'
          },

          pane: {
            startAngle: -90,
            endAngle: 89.9,
            background: null,
            center: ['50%', '75%'],
            size: '110%'
          },

          yAxis: {
            min: 0,
            max: 200,
            tickPixelInterval: 72,
            lineWidth: 0,
            plotBands: [{
                from: 0,
                to: 120,
                color: '#55BF3B', // green
                thickness: 20
            }, {
                from: 120,
                to: 160,
                color: '#DDDF0D', // yellow
                thickness: 20
            }, {
                from: 160,
                to: 200,
                color: '#DF5353', // red
                thickness: 20
            }]
          },

          series: [{
            type: undefined,
            name: 'Speed',
            data: [80],
            tooltip: {
                valueSuffix: ' km/h'
            }
          }]

        });
      })
    }
}

This is the code snippet from my comparisons.component.html:

<div class="row mt-3 bg-white p-2 pt-4 rounded box-shadow" *ngFor="let item of comparisonsStatistics.listOfJobPostComparisonStatisticsPerRound">
   <div class="container-fluid">
      <div class="row">
        <div class="col-md-12">
          <div [id]="'gaugeChart_' + item.roundNumber" style="width: 100%; height: 400px; margin: 0 auto"></div>
        </div>
      </div>
    </div>
</div>

In my comparisons.module.ts, I didn't include any service or module related to the HighCharts library since all previous charts were functioning properly. I even attempted to add HighchartsChartModule to my comparisons.module.ts thinking it might resolve the issue, but unfortunately, no changes occurred.

Answer №1

According to the JSFiddle demo in the official documentation, you need to include the "highcharts-more.js":

<script src="https://code.highcharts.com/highcharts-more.js"></script>

If you are using TypeScript, you can import the highcharts-more like this:

import * as HighCharts from 'highcharts';
import HighChartsMore from 'highcharts/highcharts-more';

HighChartsMore(HighCharts);

Check out a Sample Demo @ StackBlitz

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

Unable to delete event listeners from the browser's Document Object Model

Issue at hand involves two methods; one for initializing event listeners and the other for deleting them. Upon deletion, successful messages in the console confirm removal from the component's listener array. However, post-deletion, interactions with ...

Encountering complications in Edge browser due to triggering click on form submit button in Angular 2/4 forms

I have encountered a situation where I must trigger my form submission through code because the submit button is hidden from view. I utilize a method to simulate a button click (as there is a common button for all forms) using the following approach. cons ...

Incorporating a skeletal design effect into a table featuring sorting and pagination options

Is there a way to implement the Skeleton effect in a MUI table that only requires sorting and pagination functionalities? I tried using the 'loading' hook with fake data fetching and a 3-second delay, but it doesn't seem to work with DataGri ...

Karma Jasmin is puzzled as to why her tests are failing intermittently, despite the absence of any actual test cases

In this snippet, you will find my oninit method which I am instructed not to modify. ngOnInit(): void { this.setCustomizedValues(); this.sub = PubSub.subscribe('highlightEntity', (subId, entityIdentifier: string) => { ...

Issue with extending mongoose.Document properly in NodeJS and TypeScript using a custom interface with mongoose

I recently started learning Typescript and tried to follow this guide to help me along: After following the guide, I implemented the relevant code snippets as shown below: import { Document } from "mongoose"; import { IUser } from "../interfaces/user"; ...

Service function declaration results in the error message 'function is not a valid function.'

This particular service is designed to return an array of 1, 2, 3 for testing purposes. import {Injectable} from '@angular/core'; @Injectable() export class CitiesService { getCities() { return ['1', '2 ...

Do interfaces in Typescript require nested properties to be mandatory?

My interface contains a nested object: export interface Person { PersonWrapper: { name: string; address: string email?: string; } } When attempting to create an object from this interface, it appears that name is not mandat ...

Encountering issues in Angular 2 when attempting to pass data into root component through ng-content and binding. Objective: Creating a reusable form component

I currently have a .NET MVC application and I'm looking to integrate Angular 2 into it. The structure of my page is as follows: <html> <head>css imports and jquery imports</head> <body> <div> a bunch of table ...

What is the most effective method for managing the onSelect data within the select tag in Angular's reactive form functionality?

Can someone please advise on the best approach to handling this scenario? I have a form with multiple fields, including a select tag. <form [formGroup]="myForm"> <select formControlName="" > <option *ngFor="let c of countries" value ...

Contrasting Dependency Injection with Exporting Class Instances

I've been diving into the world of TypeScript and working on enhancing my skills as a web developer. One project I'm currently focused on is a simple ToDo app, which you can find here: https://github.com/ludersGabriel/toDo/tree/dev/backend. My q ...

Is there a way to simulate the BeforeInstallPromptEvent for testing in Jasmine/Angular?

I'm currently working on testing a dialog component that manages the PWA install event triggered manually when a specific function is invoked. The goal is to handle the promise returned by the BeforeInstallPromptEvent.userChoice property. However, wh ...

The icons within the <i> tag are failing to appear on my Ionic webpage

Trying to incorporate the tag icon in the HTML, but encountering issues with displaying the icon. Here is the code snippet I am using to display the icon, but unfortunately it's not appearing: <i class="fas fa-plus"></i> Intere ...

Bird's home - The nest is unable to sort out its dependencies

My implementation of a CryptoModule is quite straightforward: import { Module } from '@nestjs/common'; import { CryptoService } from './crypto.service'; @Module({ providers: [CryptoService], exports: [CryptoService], }) export cla ...

Uploading Files with Django Rest Framework and Angular 2

I am working with Django Rest Framework and Angular 2 to implement a file upload feature. Below is my code structure for handling files. Can anyone point out where I might be going wrong? Any help is greatly appreciated. Thank you! Django file: view cla ...

Can you explain the purpose of the "=" symbol in the function definition of "export const useAppDispatch: () => AppDispatch = useDispatch" in TypeScript?

Recently, while working on a React app that utilizes react-redux and react-toolkit, I encountered some TypeScript syntax that left me puzzled. export type RootState = ReturnType<typeof store.getState> export type AppDispatch = typeof store.dispatch e ...

Can Angular 5 integrate with Pusher?

Below is the javascript code used to integrate Pusher into native HTML: <head> <title>Pusher Test</title> <script src="https://js.pusher.com/4.1/pusher.min.js"></script> <script> // Enable pusher logging - don't i ...

transfer information from a Node.js server to an Angular client using the get() method

I am trying to access an array of data from a node.js file using angular. In my node.js file, I have the following code: app.get('/search', function(req, res){ res.send(data); }); However, I am facing difficulties retrieving this data in an ...

What is the best way to utilize the select all feature in Angular Material select components?

Is it possible for anyone to utilize the array data provided in the URL below? [{"columnName":"Column 1 - Type of Medication\n Number of Medications","selected":false},{"columnName":"Column 2 - Placebo&bsol ...

The Angular Universal client side appears to be inactive

My server-side rendered application is up and running, but I'm encountering an issue where the client-side functionality seems to be missing. Despite the routes rendering properly, none of the click events or console logs are working on the client sid ...

The function cannot accept a string as an argument, it specifically requires a Blob

Having run into a dilemma here. import React, { useState } from "react"; const PhotoUploader: React.FC = () => { const [photo, setPhoto] = useState(""); let reader = new FileReader(); reader.readAsDataURL(photo); const hand ...