-
Notifications
You must be signed in to change notification settings - Fork 391
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Angular 2 TypeScript Support in Gauge.js #128
Comments
Was I mentioned on accident? |
Hello @bernii , *Please provide any example/guide in reference to angular2 (typescript) with respect to gauge.js support if any. also inform if this is supported via typescript in angular2 |
I hope someone will provide this!!! |
Any update for this issue ? |
Or my bee version on TypeScript ? |
Here is the way to use guage.js in angular2+, HTML:
In ts: @ViewChild('gauge_1') gauge_1: ElementRef;
|
@vinothvarun94 hi, i'm trying to use your solution, i make my ts in this way:
but in this way doesn't work, what i'm doing wrong? |
you have to use (gauge_1) @ViewChild variable only for creating guage .. ie.. for all other than that you have to use .. our newly declared variable..(Gauge_1) |
i made what you say but now i have this error 'ERROR ReferenceError: Gauge is not defined', i made another mistake?
|
try..
|
import { Gauge } from 'gaugeJS/dist/gauge.min.js'; Adding this would work for issue "'Gauge' is not defined". |
Just to add to @WangJiaoJo's comment; you need to: npm i --save gaugeJS |
Here's a full example using Angular 12: Install
gaugejs.component.tsimport { AfterViewInit, Component, ElementRef, OnInit, ViewChild } from '@angular/core';
import { Gauge } from "gaugeJS";
@Component({
selector: 'app-gaugejs',
templateUrl: './gaugejs.component.html',
styleUrls: ['./gaugejs.component.scss']
})
export class GaugejsComponent implements OnInit, AfterViewInit {
@ViewChild('foo') el: ElementRef;
gauge: any;
opts: any;
ngOnInit(): void {
this.opts = {
angle: 0.15, // The span of the gauge arc
lineWidth: 0.44, // The line thickness
radiusScale: 1, // Relative radius
pointer: {
length: 0.6, // // Relative to gauge radius
strokeWidth: 0.035, // The thickness
color: '#000000' // Fill color
},
limitMax: false, // If false, max value increases automatically if value > maxValue
limitMin: false, // If true, the min value of the gauge will be fixed
colorStart: '#6FADCF', // Colors
colorStop: '#8FC0DA', // just experiment with them
strokeColor: '#E0E0E0', // to see which ones work best for you
generateGradient: true,
highDpiSupport: true, // High resolution support
};
}
ngAfterViewInit(): void {
setTimeout(() => {
var target = this.el.nativeElement as HTMLElement; // your canvas element
this.gauge = new Gauge(target).setOptions(this.opts); // create sexy gauge!
this.gauge.setMaxValue(100); // set max gauge value
this.gauge.setMinValue(0); // Prefer setter over gauge.minValue = 0
this.gauge.animationSpeed = 32; // set animation speed (32 is default value)
this.gauge.set(1250); // set actual value
}, 100)
}
} gaugejs.component.html<canvas style="width:100%;" #foo></canvas> gaugejs.component.scss:host {
display: block;
width: 100%;
max-height: 100%;
}
canvas {
width: 100% !important;
height: auto !important;
max-height: 100%;
max-width: 100%;
} |
The solution from @austenstone shows the direction but does not work on Angular 13, it does not even compile. Install
gaugejs.component.tsimport { AfterViewInit, Component, ElementRef, ViewChild } from '@angular/core';
import { Gauge, GaugeOptions } from "gaugeJS";
@Component({
selector: 'app-gaugejs',
templateUrl: './gaugejs.component.html',
styleUrls: ['./gaugejs.component.scss']
})
export class GaugejsComponent implements AfterViewInit {
@ViewChild('canvasEl') el?: ElementRef<HTMLCanvasElement>;
gauge?: Gauge;
opts?: GaugeOptions;
constructor() {
this.opts = {
angle: 0.15, // The span of the gauge arc
lineWidth: 0.44, // The line thickness
radiusScale: 1, // Relative radius
pointer: {
length: 0.6, // // Relative to gauge radius
strokeWidth: 0.035, // The thickness
color: '#000000' // Fill color
},
limitMax: true, // If false, max value increases automatically if value > maxValue
limitMin: true, // If true, the min value of the gauge will be fixed
colorStart: '#6FADCF', // Colors
colorStop: '#8FC0DA', // just experiment with them
strokeColor: '#E0E0E0', // to see which ones work best for you
generateGradient: true,
highDpiSupport: true, // High resolution support
};
}
ngAfterViewInit(): void {
if (this.el && this.el.nativeElement) {
this.gauge = new Gauge(this.el.nativeElement).setOptions(this.opts); // create sexy gauge!
this.gauge.setMinValue(0); // set min. gauge value
this.gauge.maxValue = 100; // set max. gauge value
this.gauge.animationSpeed = 32; // set animation speed (32 is default value)
this.gauge.set(60); // set actual value
}
}
} gaugejs.component.html<canvas #canvasEl></canvas> gaugejs.component.scsscanvas {
width: 100%;
height: auto;
max-height: 100%;
max-width: 100%;
} |
If you need types here is a fork #246. Seems the owner of gauge.js has been absent or not interested in TS. |
Hello,
**Please provide any example/guide in reference to angular2 (typescript) with respect to gauge.js support if any.
also inform if there is no such reference in accordance with typescript till now.**
Moreover,
i observed that there is no reference found for this speedometer in angular2(typescript).
https://groups.google.com/forum/#!msg/getgauge/FndNjpuH9Rk/bHCMx5LyBgAJ
After searching, i found this -- PLEASE CONFIRM ON THIS
The text was updated successfully, but these errors were encountered: