2025-01-08 10:31:44 +03:00
|
|
|
import { CommonModule } from '@angular/common';
|
2025-01-03 00:57:49 +03:00
|
|
|
import { Component } from '@angular/core';
|
|
|
|
|
import { ChartModule } from 'primeng/chart';
|
2025-01-03 15:48:50 +03:00
|
|
|
import { FluidModule } from 'primeng/fluid';
|
2025-01-08 10:31:44 +03:00
|
|
|
import { debounceTime, Subscription } from 'rxjs';
|
2025-01-07 13:04:10 +03:00
|
|
|
import { LayoutService } from '../../layout/service/layout.service';
|
2025-01-03 00:57:49 +03:00
|
|
|
|
|
|
|
|
@Component({
|
2025-01-07 13:04:10 +03:00
|
|
|
selector: 'app-chart-demo',
|
2025-01-07 17:29:51 +03:00
|
|
|
standalone: true,
|
|
|
|
|
imports: [CommonModule, ChartModule, FluidModule],
|
|
|
|
|
template: `
|
|
|
|
|
<p-fluid class="grid grid-cols-12 gap-8">
|
|
|
|
|
<div class="col-span-12 xl:col-span-6">
|
|
|
|
|
<div class="card">
|
|
|
|
|
<div class="font-semibold text-xl mb-4">Linear</div>
|
|
|
|
|
<p-chart type="line" [data]="lineData" [options]="lineOptions"></p-chart>
|
|
|
|
|
</div>
|
2025-01-03 00:57:49 +03:00
|
|
|
</div>
|
2025-01-07 17:29:51 +03:00
|
|
|
<div class="col-span-12 xl:col-span-6">
|
|
|
|
|
<div class="card">
|
|
|
|
|
<div class="font-semibold text-xl mb-4">Bar</div>
|
|
|
|
|
<p-chart type="bar" [data]="barData" [options]="barOptions"></p-chart>
|
|
|
|
|
</div>
|
2025-01-03 00:57:49 +03:00
|
|
|
</div>
|
2025-01-07 17:29:51 +03:00
|
|
|
<div class="col-span-12 xl:col-span-6">
|
|
|
|
|
<div class="card flex flex-col items-center">
|
|
|
|
|
<div class="font-semibold text-xl mb-4">Pie</div>
|
|
|
|
|
<p-chart type="pie" [data]="pieData" [options]="pieOptions"></p-chart>
|
|
|
|
|
</div>
|
2025-01-03 15:48:50 +03:00
|
|
|
</div>
|
2025-01-07 17:29:51 +03:00
|
|
|
<div class="col-span-12 xl:col-span-6">
|
|
|
|
|
<div class="card flex flex-col items-center">
|
|
|
|
|
<div class="font-semibold text-xl mb-4">Doughnut</div>
|
|
|
|
|
<p-chart type="doughnut" [data]="pieData" [options]="pieOptions"></p-chart>
|
|
|
|
|
</div>
|
2025-01-03 00:57:49 +03:00
|
|
|
</div>
|
2025-01-07 17:29:51 +03:00
|
|
|
<div class="col-span-12 xl:col-span-6">
|
|
|
|
|
<div class="card flex flex-col items-center">
|
|
|
|
|
<div class="font-semibold text-xl mb-4">Polar Area</div>
|
|
|
|
|
<p-chart type="polarArea" [data]="polarData" [options]="polarOptions"></p-chart>
|
|
|
|
|
</div>
|
2025-01-03 15:48:50 +03:00
|
|
|
</div>
|
2025-01-07 17:29:51 +03:00
|
|
|
<div class="col-span-12 xl:col-span-6">
|
|
|
|
|
<div class="card flex flex-col items-center">
|
|
|
|
|
<div class="font-semibold text-xl mb-4">Radar</div>
|
|
|
|
|
<p-chart type="radar" [data]="radarData" [options]="radarOptions"></p-chart>
|
|
|
|
|
</div>
|
2025-01-03 00:57:49 +03:00
|
|
|
</div>
|
2025-01-07 17:29:51 +03:00
|
|
|
</p-fluid>
|
|
|
|
|
`
|
2025-01-03 00:57:49 +03:00
|
|
|
})
|
2025-01-07 13:04:10 +03:00
|
|
|
export class ChartDemo {
|
2025-01-03 00:57:49 +03:00
|
|
|
lineData: any;
|
|
|
|
|
|
|
|
|
|
barData: any;
|
|
|
|
|
|
|
|
|
|
pieData: any;
|
|
|
|
|
|
|
|
|
|
polarData: any;
|
|
|
|
|
|
|
|
|
|
radarData: any;
|
|
|
|
|
|
|
|
|
|
lineOptions: any;
|
|
|
|
|
|
|
|
|
|
barOptions: any;
|
|
|
|
|
|
|
|
|
|
pieOptions: any;
|
|
|
|
|
|
|
|
|
|
polarOptions: any;
|
|
|
|
|
|
|
|
|
|
radarOptions: any;
|
|
|
|
|
|
|
|
|
|
subscription: Subscription;
|
|
|
|
|
constructor(private layoutService: LayoutService) {
|
2025-01-07 17:29:51 +03:00
|
|
|
this.subscription = this.layoutService.configUpdate$.pipe(debounceTime(25)).subscribe(() => {
|
|
|
|
|
this.initCharts();
|
|
|
|
|
});
|
2025-01-03 00:57:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ngOnInit() {
|
|
|
|
|
this.initCharts();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
initCharts() {
|
|
|
|
|
const documentStyle = getComputedStyle(document.documentElement);
|
2025-01-06 16:42:04 +03:00
|
|
|
const textColor = documentStyle.getPropertyValue('--p-text-color');
|
|
|
|
|
const textColorSecondary = documentStyle.getPropertyValue('--p-text-muted-color');
|
|
|
|
|
const surfaceBorder = documentStyle.getPropertyValue('--p-content-border-color');
|
2025-01-03 00:57:49 +03:00
|
|
|
|
|
|
|
|
this.barData = {
|
|
|
|
|
labels: ['January', 'February', 'March', 'April', 'May', 'June', 'July'],
|
|
|
|
|
datasets: [
|
|
|
|
|
{
|
|
|
|
|
label: 'My First dataset',
|
2025-01-06 16:42:04 +03:00
|
|
|
backgroundColor: documentStyle.getPropertyValue('--p-primary-500'),
|
|
|
|
|
borderColor: documentStyle.getPropertyValue('--p-primary-500'),
|
2025-01-03 00:57:49 +03:00
|
|
|
data: [65, 59, 80, 81, 56, 55, 40]
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
label: 'My Second dataset',
|
2025-01-06 16:42:04 +03:00
|
|
|
backgroundColor: documentStyle.getPropertyValue('--p-primary-200'),
|
|
|
|
|
borderColor: documentStyle.getPropertyValue('--p-primary-200'),
|
2025-01-03 00:57:49 +03:00
|
|
|
data: [28, 48, 40, 19, 86, 27, 90]
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
this.barOptions = {
|
|
|
|
|
plugins: {
|
|
|
|
|
legend: {
|
|
|
|
|
labels: {
|
2025-01-08 10:31:44 +03:00
|
|
|
color: textColor
|
2025-01-03 00:57:49 +03:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
scales: {
|
|
|
|
|
x: {
|
|
|
|
|
ticks: {
|
|
|
|
|
color: textColorSecondary,
|
|
|
|
|
font: {
|
|
|
|
|
weight: 500
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
grid: {
|
|
|
|
|
display: false,
|
|
|
|
|
drawBorder: false
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
y: {
|
|
|
|
|
ticks: {
|
|
|
|
|
color: textColorSecondary
|
|
|
|
|
},
|
|
|
|
|
grid: {
|
|
|
|
|
color: surfaceBorder,
|
|
|
|
|
drawBorder: false
|
|
|
|
|
}
|
2025-01-07 17:29:51 +03:00
|
|
|
}
|
2025-01-03 00:57:49 +03:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
this.pieData = {
|
|
|
|
|
labels: ['A', 'B', 'C'],
|
|
|
|
|
datasets: [
|
|
|
|
|
{
|
|
|
|
|
data: [540, 325, 702],
|
2025-01-07 17:29:51 +03:00
|
|
|
backgroundColor: [documentStyle.getPropertyValue('--p-indigo-500'), documentStyle.getPropertyValue('--p-purple-500'), documentStyle.getPropertyValue('--p-teal-500')],
|
|
|
|
|
hoverBackgroundColor: [documentStyle.getPropertyValue('--p-indigo-400'), documentStyle.getPropertyValue('--p-purple-400'), documentStyle.getPropertyValue('--p-teal-400')]
|
|
|
|
|
}
|
|
|
|
|
]
|
2025-01-03 00:57:49 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
this.pieOptions = {
|
|
|
|
|
plugins: {
|
|
|
|
|
legend: {
|
|
|
|
|
labels: {
|
|
|
|
|
usePointStyle: true,
|
|
|
|
|
color: textColor
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
this.lineData = {
|
|
|
|
|
labels: ['January', 'February', 'March', 'April', 'May', 'June', 'July'],
|
|
|
|
|
datasets: [
|
|
|
|
|
{
|
|
|
|
|
label: 'First Dataset',
|
|
|
|
|
data: [65, 59, 80, 81, 56, 55, 40],
|
|
|
|
|
fill: false,
|
2025-01-06 16:42:04 +03:00
|
|
|
backgroundColor: documentStyle.getPropertyValue('--p-primary-500'),
|
|
|
|
|
borderColor: documentStyle.getPropertyValue('--p-primary-500'),
|
2025-01-07 17:29:51 +03:00
|
|
|
tension: 0.4
|
2025-01-03 00:57:49 +03:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
label: 'Second Dataset',
|
|
|
|
|
data: [28, 48, 40, 19, 86, 27, 90],
|
|
|
|
|
fill: false,
|
2025-01-06 16:42:04 +03:00
|
|
|
backgroundColor: documentStyle.getPropertyValue('--p-primary-200'),
|
|
|
|
|
borderColor: documentStyle.getPropertyValue('--p-primary-200'),
|
2025-01-07 17:29:51 +03:00
|
|
|
tension: 0.4
|
2025-01-03 00:57:49 +03:00
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
this.lineOptions = {
|
|
|
|
|
plugins: {
|
|
|
|
|
legend: {
|
|
|
|
|
labels: {
|
2025-01-08 10:31:44 +03:00
|
|
|
color: textColor
|
2025-01-03 00:57:49 +03:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
scales: {
|
|
|
|
|
x: {
|
|
|
|
|
ticks: {
|
|
|
|
|
color: textColorSecondary
|
|
|
|
|
},
|
|
|
|
|
grid: {
|
|
|
|
|
color: surfaceBorder,
|
|
|
|
|
drawBorder: false
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
y: {
|
|
|
|
|
ticks: {
|
|
|
|
|
color: textColorSecondary
|
|
|
|
|
},
|
|
|
|
|
grid: {
|
|
|
|
|
color: surfaceBorder,
|
|
|
|
|
drawBorder: false
|
|
|
|
|
}
|
2025-01-07 17:29:51 +03:00
|
|
|
}
|
2025-01-03 00:57:49 +03:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
this.polarData = {
|
2025-01-07 17:29:51 +03:00
|
|
|
datasets: [
|
|
|
|
|
{
|
|
|
|
|
data: [11, 16, 7, 3],
|
|
|
|
|
backgroundColor: [documentStyle.getPropertyValue('--p-indigo-500'), documentStyle.getPropertyValue('--p-purple-500'), documentStyle.getPropertyValue('--p-teal-500'), documentStyle.getPropertyValue('--p-orange-500')],
|
|
|
|
|
label: 'My dataset'
|
|
|
|
|
}
|
|
|
|
|
],
|
|
|
|
|
labels: ['Indigo', 'Purple', 'Teal', 'Orange']
|
2025-01-03 00:57:49 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
this.polarOptions = {
|
|
|
|
|
plugins: {
|
|
|
|
|
legend: {
|
|
|
|
|
labels: {
|
|
|
|
|
color: textColor
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
scales: {
|
|
|
|
|
r: {
|
|
|
|
|
grid: {
|
|
|
|
|
color: surfaceBorder
|
2025-01-08 12:31:25 +03:00
|
|
|
},
|
|
|
|
|
ticks: {
|
|
|
|
|
display: false
|
2025-01-03 00:57:49 +03:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
this.radarData = {
|
|
|
|
|
labels: ['Eating', 'Drinking', 'Sleeping', 'Designing', 'Coding', 'Cycling', 'Running'],
|
|
|
|
|
datasets: [
|
|
|
|
|
{
|
|
|
|
|
label: 'My First dataset',
|
2025-01-06 16:42:04 +03:00
|
|
|
borderColor: documentStyle.getPropertyValue('--p-indigo-400'),
|
|
|
|
|
pointBackgroundColor: documentStyle.getPropertyValue('--p-indigo-400'),
|
|
|
|
|
pointBorderColor: documentStyle.getPropertyValue('--p-indigo-400'),
|
2025-01-03 00:57:49 +03:00
|
|
|
pointHoverBackgroundColor: textColor,
|
2025-01-06 16:42:04 +03:00
|
|
|
pointHoverBorderColor: documentStyle.getPropertyValue('--p-indigo-400'),
|
2025-01-03 00:57:49 +03:00
|
|
|
data: [65, 59, 90, 81, 56, 55, 40]
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
label: 'My Second dataset',
|
2025-01-06 16:42:04 +03:00
|
|
|
borderColor: documentStyle.getPropertyValue('--p-purple-400'),
|
|
|
|
|
pointBackgroundColor: documentStyle.getPropertyValue('--p-purple-400'),
|
|
|
|
|
pointBorderColor: documentStyle.getPropertyValue('--p-purple-400'),
|
2025-01-03 00:57:49 +03:00
|
|
|
pointHoverBackgroundColor: textColor,
|
2025-01-06 16:42:04 +03:00
|
|
|
pointHoverBorderColor: documentStyle.getPropertyValue('--p-purple-400'),
|
2025-01-03 00:57:49 +03:00
|
|
|
data: [28, 48, 40, 19, 96, 27, 100]
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
this.radarOptions = {
|
|
|
|
|
plugins: {
|
|
|
|
|
legend: {
|
|
|
|
|
labels: {
|
2025-01-08 10:31:44 +03:00
|
|
|
color: textColor
|
2025-01-03 00:57:49 +03:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
scales: {
|
|
|
|
|
r: {
|
2025-01-08 12:27:10 +03:00
|
|
|
pointLabels: {
|
|
|
|
|
color: textColor
|
|
|
|
|
},
|
2025-01-03 00:57:49 +03:00
|
|
|
grid: {
|
|
|
|
|
color: textColorSecondary
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ngOnDestroy() {
|
|
|
|
|
if (this.subscription) {
|
|
|
|
|
this.subscription.unsubscribe();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|