Angular UI Components Documentation
The Angular Draw is a low-level drawing API for SVG and Canvas shapes, text and paths. This guide adds the Angular Draw (jqxDraw) to an app, then shows how to set its options and call its methods.
jqwidgets-ngjqwidgets-ng/jqxdraw 
In an Angular project (to start one, see Getting started with Angular), add the package with the Angular CLI. It asks for a theme and adds the styles to angular.json:
ng add jqwidgets-ng
Components are standalone: add jqxDrawModule to the imports of the component that uses it.
import { Component } from '@angular/core';
import { jqxDrawModule } from 'jqwidgets-ng/jqxdraw';
@Component({
selector: 'app-root',
imports: [jqxDrawModule],
templateUrl: './app.html'
})
export class App {}
The source of the live Drawing Shapes demo.
<jqxDraw #myDraw [width]="getWidth()" [height]="500"></jqxDraw>
import { Component, AfterViewInit, ViewEncapsulation, viewChild } from '@angular/core';
import { jqxDrawComponent } from 'jqwidgets-ng/jqxdraw';
import { CommonModule } from '@angular/common';
import { jqxDrawModule } from 'jqwidgets-ng/jqxdraw';
@Component({
imports: [CommonModule, jqxDrawModule],
selector: 'app-root',
templateUrl: './app.html',
styleUrl: './app.css',
encapsulation: ViewEncapsulation.None
})
export class App implements AfterViewInit {
readonly myDraw = viewChild.required<jqxDrawComponent>('myDraw');
getWidth(): any {
if (document.body.offsetWidth < 800) {
return '90%';
}
return 800;
}
ngAfterViewInit(): void {
let size = this.myDraw().getSize();
let circleElement = this.myDraw().circle(250, 150, 50, {});
this.myDraw().attr(circleElement, { fill: 'lightblue', stroke: 'darkblue' });
let borderElement = this.myDraw().rect(0, 0, size.width, size.height, {
stroke: '#777777',
fill: 'transparent'
});
let pathElement = this.myDraw().path('M 100,100 L 150, 130 C 130,130 180,190 150,150', {
stroke: '#777777',
fill: 'red'
});
let areaElement = this.myDraw().path('M 300,300 L 350, 330 C 330,330 380,390 350,350 Z', {
stroke: '#777777',
fill: 'yellow'
});
this.myDraw().line(600, 100, 600, 200, { stroke: 'blue', 'stroke-width': 6 });
this.myDraw().line(550, 50, 650, 90, { stroke: 'green', 'stroke-width': 6 });
this.myDraw().text(
'Drawing shapes',
50,
20,
undefined,
undefined,
0,
{ class: 'largeText', fill: 'yellow', stroke: 'orange' },
false,
'center',
'center',
'centermiddle'
);
this.myDraw().text(
'This is rotated text',
600,
300,
undefined,
undefined,
45,
{ class: 'smallText' },
false,
'center',
'center',
'centermiddle'
);
let circleUp = this.myDraw().circle(50, 450, 30, { fill: '#DEDEDE', stroke: '#777777' });
let pathUp = this.myDraw().path('M30 460 L 70 460 L50 430 Z', {
fill: 'transparent',
stroke: '#777777',
'stroke-width': 1
});
let circleDown = this.myDraw().circle(120, 450, 30, { fill: '#DEDEDE', stroke: '#777777' });
let pathDown = this.myDraw().path('M100 440 L 140 440 L120 470 Z', {
fill: 'transparent',
stroke: '#777777',
'stroke-width': 1
});
this.myDraw().text('Click these buttons:', 20, 390);
let moveCircle = (moveUp: boolean): void => {
let circleY = parseInt(this.myDraw().getAttr(circleElement, 'cy'));
this.myDraw().attr(circleElement, { cy: circleY + (moveUp ? -10 : 10) });
};
this.myDraw().on(circleUp, 'click', (): void => {
moveCircle(true);
});
this.myDraw().on(pathUp, 'click', (): void => {
moveCircle(true);
});
this.myDraw().on(circleDown, 'click', (): void => {
moveCircle(false);
});
this.myDraw().on(pathDown, 'click', (): void => {
moveCircle(false);
});
this.myDraw().refresh();
}
}.smallText {
font-size: 16px;
font-family: Sans-Serif;
}
.largeText {
font-size: 36px;
font-family: Sans-Serif;
}
Options are inputs, bound with [name]="value".
Get the component with a signal query and call its methods. For example, refresh: Refreshes / re-draws the content of the jqxDraw widget
<jqxDraw #myDraw></jqxDraw>
import { Component, viewChild } from '@angular/core';
import { jqxDrawModule, jqxDrawComponent } from 'jqwidgets-ng/jqxdraw';
@Component({
selector: 'app-root',
imports: [jqxDrawModule],
templateUrl: './app.html'
})
export class App {
readonly myDraw = viewChild.required<jqxDrawComponent>('myDraw');
run(): void {
this.myDraw().refresh();
}
}