Search code examples
angulartypescriptmorris.js

How to integrate Morris JS chart library into Angular?


I want to use the Morris.js plugin on an Angular project. I know how to use jQuery plugins inside an Angular application. But I can't figure out how to integrate Morris Chart into my Angular app. Please give me some advice if you have a similar experience.


Solution

  • I solve this problem using same way to use jQuery. Please look at following codes.

    declare var $: any;
    declare var Morris: any;
    ...
    ngOnInit() {
       Morris.Bar({
          element: 'morris-bar',
          data: [
            {
              x: '2017 R1',
              y: 3,
              z: 2,
              a: 3,
            },
       ......
       xkey: 'X',
       kyes: ['y', 'z', 'a'],
       ...
       });
    }