1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
|
import { AfterViewInit, Component, OnDestroy, OnInit } from '@angular/core';
import { NbThemeService, NbColorHelper } from '@nebular/theme';
import { RestApiService } from '../../../shared/rest-api/rest-api.service';
@Component({
selector: 'ngx-chartjs-bar',
template: `
<chart type="bar" [data]="data" [options]="options"></chart>
`,
})
export class ChartjsBarComponent implements OnDestroy, OnInit, AfterViewInit {
data: any;
options: any;
themeSubscription: any;
getHistoryOfContainers(): any{
this.dataService.getHistoryOfContainerDeployment().subscribe((res)=>{
this.data.labels = res.labels;
this.data.datasets[0].data = res.running;
this.data.datasets[1].data = res.paused;
this.data.datasets[2].data = res.stopped;
this.data.datasets[3].data = res.failed;
});
}
ngOnInit() {
console.log("passé"); // s'affiche à chaque chargement de page.
this.themeSubscription = this.theme.getJsTheme().subscribe(config => {
const colors: any = config.variables;
const chartjs: any = config.variables.chartjs;
this.data = {
labels: ['Loading...','Loading...','Loading...','Loading...','Loading...','Loading...','Loading...', 'Loading...', 'Loading...', 'Loading...', 'Loading...', 'Loading...'],
datasets: [{
data: [0,0,0,0,0,0,0,0,0,0,0,0],
label: 'Running',
backgroundColor: NbColorHelper.hexToRgbA(colors.success, 0.8),
}, {
data: [0,0,0,0,0,0,0,0,0,0,0,0],
label: 'Paused',
backgroundColor: NbColorHelper.hexToRgbA(colors.warning, 0.8),
},
{
data: [0,0,0,0,0,0,0,0,0,0,0,0],
label: 'Stopped',
backgroundColor: NbColorHelper.hexToRgbA(colors.dangerLight, 0.8),
},
{
data: [0,0,0,0,0,0,0,0,0,0,0,0],
label: 'Failed',
backgroundColor: NbColorHelper.hexToRgbA(colors.danger, 0.8),
}],
};
this.options = {
maintainAspectRatio: false,
responsive: true,
legend: {
labels: {
fontColor: chartjs.textColor,
},
},
scales: {
xAxes: [
{
gridLines: {
display: false,
color: chartjs.axisLineColor,
},
ticks: {
fontColor: chartjs.textColor,
},
},
],
yAxes: [
{
gridLines: {
display: true,
color: chartjs.axisLineColor,
},
ticks: {
fontColor: chartjs.textColor,
beginAtZero: true,
callback: function(value) {if (value % 1 === 0) {return value;}}
},
},
],
},
};
});
this.getHistoryOfContainers();
}
constructor(private theme: NbThemeService, private dataService: RestApiService) {
}
ngOnDestroy(): void {
this.themeSubscription.unsubscribe();
}
} |
Partager