What is the best way to implement a Highcharts Solid Gauge in Angular 6 using TypeScript?

In my ongoing project, I am utilizing Angular 6 along with TypeScript. The objective is to incorporate a Solidgauge in one of my Components. However, as I proceeded with the development of this component, I encountered some challenges:

When attempting to display the Gauge on the interface, nothing appears, and Highcharts error #17 is displayed in the console. My suspicion is that the issue stems from how I imported Highcharts-more into my component.

Contents of my throughput.component.ts file

import { Component, OnInit, OnDestroy, Input} from '@angular/core';
import { UsageService } from '../../services/UsageService';
import { Subscription } from 'rxjs';
import * as Highcharts from 'highcharts/highcharts';
import 'highcharts/modules/exporting';
import * as more from 'highcharts-more/more';
import * as solidgauge from 'highcharts/modules/solid-gauge';
more(Highcharts);

@Component({
  selector: 'app-throughput',
  templateUrl: './throughput.component.html',
  styleUrls: ['./throughput.component.css'],
})

export class ThroughputComponent implements OnInit, OnDestroy {
  public messageCount: number;
  public chart: any;

 constructor() {
   this.messageCount = 0;
 }

 ngOnInit(): void {
   this.initChart(this.buildGauge());
 }

 ngOnDestroy() {}

 private buildGauge(): any {
    return {
      // Chart configuration here...
    };
}

private initChart(gaugeOptions: any) {
  this.chart = Highcharts.chart('gauge-container', 
              Highcharts.merge(gaugeOptions, {
   // Additional options for the chart.
  }));
}

Contents of my throughput.component.html file

<div id='gauge-container' style="width: 300px; height: 200px"></div>

Contents of my app.module.ts

import { BrowserModule } from '@angular/platform-browser';
// Other imports...

@NgModule({
  declarations: [
     // Components declared here
   ],
   imports: [
     BrowserModule,
     BrowserAnimationsModule,
     MatCardModule,
     MatButtonModule,
     MatGridListModule,
     RouterModule.forRoot([
       // Routes defined here
     ])
   ],
   providers: [GatewayService],
   bootstrap: [AppComponent]
 })
 export class AppModule { }

If anyone could provide insight into what might be going awry in my implementation or if there are steps I may have overlooked, it would be greatly appreciated.

Note: In the most recent iteration of my code, I attempted separate installations of highcharts-more and highcharts via npm.

Answer №1

Ensure to include the following:

  • highcharts library
  • highcharts-more extension
  • solid-gauge module

Here's a sample implementation:

import * as Highcharts from 'highcharts/highcharts.min';
import * as HighchartsMore from 'highcharts/highcharts-more.min';
import * as SolidGaugeModule from 'highcharts/modules/solid-gauge';

// Initialize the modules:
HighchartsMore(Highcharts);
SolidGaugeModule(Highcharts);

Answer №2

To enhance the solution provided by Pawel Fus and in accordance with the guidance from the documentation of the angular-highcharts library:

// app.module.ts
import { ChartModule, HIGHCHARTS_MODULES } from 'angular-highcharts'
import * as HighchartsMore from 'highcharts/highcharts-more.src'
import * as HighchartsSolidGauge from 'highcharts/modules/solid-gauge'

...
imports: [ ChartModule ],
providers: [
    { 
        provide: HIGHCHARTS_MODULES, 
        useFactory: () => [HighchartsMore, HighchartsSolidGauge] 
    },
]
...

Answer №3

import * as Highcharts from 'highcharts/highcharts';
import * as HighchartsMore from 'highlighter/highcharts-more';
import * as HighchartsSolidGauge from 'highcharts/plugins/solid-gauge'; 
HighchartsMore(Highcharts);
HighchartsSolidGauge(Highcharts);

The snippet above is causing some issues for me, but after making some adjustments the following code works perfectly fine. I am using Angular CLI version 9.1.7.

import * as Highcharts from 'highcharts/highcharts';
import HighchartsMore from 'highcharts/highcharts-more.src';
import HighchartsSolidGauge from 'highcharts/plugins/solid-gauge';

HighchartsMore(Highcharts);
HighchartsSolidGauge(Highcharts);

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

Endless scrolling feature malfunctioning

On my profile_page.php, the default setting is to display 10 posts (10 rows from the database) for the user. If a user has more than 10 posts, and scrolls to the bottom of the page, the div should expand to reveal the remaining posts (maximum of 10). For e ...

Initiate function directly through computed property (Vue.js)

I'm currently working on a project using Vue 3 along with VueX. I am wondering if there is a way to check within the computed property whether the value returned is true, and then directly trigger my method without needing a watcher. A bit of backgr ...

Which is quicker in JavaScript: appending a string or an array?

Which one is quicker? let str = ''; for(let i=0; i<1000; i++) { str += i; } or let arr = []; for(let i=0; i<1000; i++) { arr.push(i); } let str = arr.join(''); I am curious about the speed difference between these two ...

Where is the first next() call's argument located?

I'm facing an issue with a simple generator function function *generate(arg) { console.log(arg) for(let i = 0; i < 3;i++) { console.log(yield i); } } After initializing the generator, I attempted to print values in the console: var gen ...

Applying hover effect to material-ui IconButton component

As stated in the React Material-UI documentation, I have access to a prop called hoveredStyle: http://www.material-ui.com/#/components/icon-button I intend to utilize the IconButton for two specific purposes: Make use of its tooltip prop for improved ac ...

A runtime error occurred in ScriptResource.axd at line var f = ($telerik.isIE) ? document.createElement('<iframe name="' + this.get_id() + '">');

I am encountering an error during runtime in the ScriptResource.axd file, which is causing a major issue for me as I am unable to modify the code directly to fix it. The error seems to be specific to this line: ScriptResource.axd runtime error on line var ...

When using Rspec and Capybara, utilizing jQuery to set focus on an element may not apply the `:focus` CSS as expected

I have implemented jump links for blind and keyboard users on my website, but I've hidden them off-screen visually. When these links gain focus, they are moved into the viewport. Trying to test this behavior using RSpec and Capybara has been unsucces ...

Angular: The Ultimate Guide to Reloading a Specific Section of HTML (Form/Div/Table)

On my create operation page, I have a form with two fields. When I reload the page using window.reload in code, I can see updates in the form. However, I want to trigger a refresh on the form by clicking a button. I need help writing a function that can r ...

The validation functionality in AngularJS for a form within an ng-repeat loop is not functioning as intended

In my table, I used the <tr> tag repeatedly with ng-repeat="cancellationPercentData in cancellationPercent" Each tr tag contains a form with name and id set using $index See the code snippet below: <tbody> <tr ng-repeat="cancellatio ...

Ways to populate dynamic choices for multiple Select boxes within an ng-repeat loop

When I click the "Add Row" button on an Html form, dynamic rows are added. Each row contains a 'Country' select and a 'State' select. The issue I am facing is that when I select a country in one row, all other row values change as well. ...

Loop through a non-array or non-object / handling both arrays and non-arrays equally

Sometimes, I find myself needing to handle arrays and single objects in a similar manner. For instance, I may have an object property that can be either an array or just a string (like the scale property): [ { "name": "Experiment type14", "id": ...

Utilizing Vuejs to initiate a GET request using a method

Currently, I am working on enhancing the functionality of a GET request in Vue. My goal is to attach the request sending action to the form's submit button and also include a parameter from a text field within the form. HTML <html> <head> ...

Place an entire element within another element, rather than just inserting its inner HTML contents

I'm currently exploring the use of jQuery to generate HTML content with ease. My intention was to create <div><span>Alice</span></div> using the code shown below, but instead, I ended up with <div>[object Object]</div& ...

Guide to exporting everything within a div as a PDF using Angular 2

When attempting to convert a div with the id "div1" into a PDF using JSPdf in Angular 2, everything seems to be working fine until I try to export it to PDF. Here is my code snippet: <div class="container" id="div1"> <table> <tr> & ...

Utilize CSS animation classes on multiple elements throughout a single webpage

Trying to create a share button for social media with an animated button using CSS. However, encountering issues when trying to display multiple buttons on the same page for different content. The problem arises when clicking the second button, as it trigg ...

Implementing a dynamic navbar in Vue.js using Firebase authentication

I've been diving into a Vue.js project that allows users to sign up and log in. I've incorporated Firebase Authentication for the login and sign up functionality. Successfully, I've implemented the feature where the navbar state changes: whe ...

verifying the presence of offspring in knockout js

Utilizing knockout for displaying items on the page, I have a series of groups such as Group 1, Group 2, etc. Each group is contained within its own div. Upon clicking on a group, it expands to showcase the items within that specific group. However, some o ...

When there are multiple tabs open in the browser, I notice a difference in the time displayed. This occurs in an Angular 2 environment

https://i.sstatic.net/l4YQ1.pngAfter a successful login, I am fetching server time from the back-end (in Java) and adding 1 second at intervals. Observable.interval(1000).map(() => { return this.time.add(1, 'seconds'); }). ...

Obtaining the attribute value from a custom tag in Angular: A comprehensive guide

I am currently working on creating a customized password component in Angular5. I am having difficulty obtaining the minimum and maximum attribute values required to validate the password. I attempted to retrieve the values using JavaScript's getAttr ...

Is it possible to incorporate the arrow function within the debounce function?

export const debounce = (callback: Function, ms = 300) => { let timeoutId: ReturnType<typeof setTimeout> return function (...args: any[]) { clearTimeout(timeoutId) timeoutId = setTimeout(() => callback.apply(this, args), ms) ...