How to create a custom directive that integrates with external charting libraries

0 votes
Can Someone help me regarding How to create a custom directive that integrates with external charting libraries?
2 days ago in Angular by Nidhi
• 14,600 points
22 views

1 answer to this question.

0 votes

Compact Directive for External Chart Integration

import { Directive, ElementRef, Input, OnChanges, OnDestroy } from '@angular/core';  

import * as ChartJS from 'chart.js';  

@Directive({  

  selector: '[appChart]'  

})  

export class ChartDirective implements OnChanges, OnDestroy {  

  @Input() config: any;  

  private chart: any;  

  constructor(private el: ElementRef) {}  

  ngOnChanges() {  

    if (this.chart) this.chart.destroy();  

    this.chart = new ChartJS.Chart(this.el.nativeElement, this.config);  

  }  

  ngOnDestroy() {  

    if (this.chart) this.chart.destroy();  

  }  

}  

Usage:

<canvas appChart [config]="chartConfig"></canvas>

answered 2 days ago by anonymous

Related Questions In Angular

0 votes
1 answer

How to implement a directive that manages focus on dynamically added elements?

To implement a directive that manages focus ...READ MORE

answered 2 days ago in Angular by anonymous
32 views
0 votes
1 answer

How to build a directive that listens for specific keyboard shortcuts?

You can use the @HostListener decorator to ...READ MORE

answered 2 days ago in Angular by anonymous
42 views
0 votes
1 answer
0 votes
0 answers

How do Observables improve API call handling in Angular?

With the help of an example, can ...READ MORE

Mar 3 in Angular by Nidhi
• 14,600 points
107 views
0 votes
0 answers

What’s the difference between Observables and Promises?

With the help of an example, can ...READ MORE

Mar 3 in Angular by Nidhi
• 14,600 points
76 views
0 votes
0 answers

What type of operation do RxJS operators allow for observables?

With the help of an example, can ...READ MORE

Mar 3 in Angular by Nidhi
• 14,600 points
85 views
0 votes
0 answers

When to use switchMap vs concatMap?

With the help of an example, can ...READ MORE

Mar 3 in Angular by Nidhi
• 14,600 points
111 views
0 votes
1 answer

How to implement a directive that adds tooltips to form controls dynamically?

Custom Tooltip Directive 1. Create the Directive import { ...READ MORE

answered 2 days ago in Angular by anonymous
20 views
0 votes
1 answer

How to develop a directive that modifies element styles based on form validation status?

Here's a concise directive that automatically applies ...READ MORE

answered 2 days ago in Angular by anonymous
21 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP