Share this

Highcharts with Angular V14

Haroon Ansari Avatar

by

2 minutes read

Picture of angular-and-highcharts

With the release of angular version 14, standalone components have been introduced, and NgModule became optional; facilitating a new way of building and structuring the codebase.

In this article, we will create a chart and see how to use and integrate angular standalone components along with the official Highcharts Angular wrapper.

Let’s get started 🙂

To create a project with the latest version of Angular, for starters update the angular-cli package with the following commands:

npm uninstall -g @angular/cli 	
npm install -g @angular/cli@latest

For this project, we are using:

The project is set up using an Angular application environment and workspace with the following settings:

  • Node: 14.17.0
  • npm 8.3.1
  • Angular CLI: 14.0.2.

Set up an Angular project with Highcharts

  1. 1.

    If you are unfamiliar with this type of environment, the official Angular documentation describes how to set up a local environment workspace, and more about the standalone component.

  2. 2.

    To install highcharts-angular and the Highcharts library run the following instruction: npm install highcharts-angular --save.

  3. 3.

    To import the package go to app.module.ts file and import the module HighchartsChartModule from the highcharts-angular package.

  4. 4.

    To build Highcharts charts, install Highcharts: npm install highcharts --save.

  5. 5.

    We are declaring app.compoent.ts as a standalone component and importing the HighchartsChartModule inside imports array instead of NgModule (optional). Application level dependencies such as routes, dependency injection configure in the main.ts and component level in app.component.ts or any other component.

@Component({
  selector: 'my-app',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css'],
  standalone: true,
  imports: [HighchartsChartModule],
})

6. Bootstrap the app from main.ts.

import "./polyfills";
import { bootstrapApplication } from "@angular/platform-browser";
import { AppComponent } from "./app/app.component";
bootstrapApplication(AppComponent);

7. Click on this Stackblitz project to find the complete working example with code. Here is the final result:

Feel free to share your thoughts and questions in the comments below.

Stay in touch

No spam, just good stuff

We're on discord. Join us for challenges, fun and whatever else we can think of
XSo MeXSo Me Dark
Linkedin So MeLinkedin So Me Dark
Facebook So MeFacebook So Me Dark
Github So MeGithub So Me Dark
Youtube So MeYoutube So Me Dark
Instagram So MeInstagram So Me Dark
Stackoverflow So MeStackoverflow So Me Dark
Discord So MeDiscord So Me Dark

Comments

  1. Imran

    |

    I want to send a pm
    Exchange


  2. Mustapha Mekhatria

    |

    Hi,
    Feel free to get in touch with our tech support 🙂


  3. Samiullah Khan

    |

    When I use highchart directly (without any angular wrapper) I get following warning in cli

    “CommonJS or AMD dependencies can cause optimization bailouts”

    Will using this package solve them and ensure that es module is used?


    1. Mustapha Mekhatria

      |

      Hi,
      Feel free to get in touch with our tech support 🙂


  4. torkil Pedersen

    |

    Is there plan for Angular V 15 support


    1. Mustapha Mekhatria

      |

      Hi,
      The highcharts-angular wrapper works with Angular 15. Check the following example: https://stackblitz.com/edit/highcharts-angular-line


      1. Kintela

        |

        Hi

        I just installed highchart in my Angular 14 project

        “highcharts”: “^11.0.1”,
        “highcharts-angular”: “^3.1.2”,

        But when I execute ng serve -o I Get this error
        node_modules/highcharts-angular/lib/highcharts-chart.component.d.ts:24:18 – error TS2707: Generic type ‘ɵɵComponentDeclaration’ requires between 7 and 8 type arguments.

        24 static ɵcmp: i0.ɵɵComponentDeclaration;
        Any idea please?
        Thanks


        1. Danu Rosca

          |

          try to use
          “highcharts”: “^11.0.1”,
          “highcharts-angular”: “3.0.0”,
          because highcharts-angular have a problem with version 14 of angular


  5. Srinivas

    |

    Hi,
    I am using Angular-highcharts with Angular 16, and I am not able to use the chat more than once in a component.


    1. Mustapha Mekhatria

      |

      Hi,
      Please, feel feel to get in touch with our support https://www.highcharts.com/support/


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.