add 2hr chart

This commit is contained in:
Ben Wilson
2023-06-25 16:35:29 -04:00
parent 0c0ca21ac8
commit b3302fb84c
2 changed files with 42 additions and 9 deletions

View File

@@ -63,9 +63,9 @@
</div> </div>
<div class="col-12" *ngIf="chartData$ | async as chartData"> <div *ngIf="chartData$ | async as chartData">
<div class="card"> <div class="card">
<p-chart type="line" [data]="chartData" [options]="chartOptions"></p-chart> <p-chart [data]="chartData" [options]="chartOptions"></p-chart>
</div> </div>
</div> </div>

View File

@@ -34,17 +34,51 @@ export class DashboardComponent {
this.chartData$ = this.clientInfo$.pipe( this.chartData$ = this.clientInfo$.pipe(
map((workerInfo: any) => { map((workerInfo: any) => {
const hourly = (workerInfo.chartData as any[]).reduce((pre, cur, idx, arr) => {
if (idx % 11 == 0 && idx != 0) {
pre[pre.length - 1].y = pre[pre.length - 1].y / 12;
}
if (idx + 11 > arr.length) {
return pre;
}
if (idx % 11 == 0) {
pre.push({ y: cur.data, x: cur.label });
}
pre[pre.length - 1].y += cur.data;
return pre;
}, []);
const data = workerInfo.chartData.map((d: any) => { return { y: d.data, x: d.label } });
return { return {
labels: workerInfo.chartData.map((d: any) => d.label), labels: workerInfo.chartData.map((d: any) => d.label),
datasets: [ datasets: [
{ {
label: address, type: 'line',
data: workerInfo.chartData.map((d: any) => d.data), label: '2 Hour',
data: hourly,
fill: false,
backgroundColor: documentStyle.getPropertyValue('--primary-color'),
borderColor: documentStyle.getPropertyValue('--primary-color'),
tension: .4
},
{
type: 'line',
label: '5 Minute',
data: data,
fill: false, fill: false,
backgroundColor: documentStyle.getPropertyValue('--bluegray-700'), backgroundColor: documentStyle.getPropertyValue('--bluegray-700'),
borderColor: documentStyle.getPropertyValue('--bluegray-700'), borderColor: documentStyle.getPropertyValue('--bluegray-700'),
tension: .4 tension: .4
} },
] ]
} }
}) })
@@ -64,16 +98,15 @@ export class DashboardComponent {
x: { x: {
type: 'time', type: 'time',
time: { time: {
unit: 'minute', // Set the unit to 'minute' unit: 'hour', // Set the unit to 'minute'
stepSize: 10, // Set the desired interval between labels in minutes
}, },
ticks: { ticks: {
color: textColorSecondary color: textColorSecondary
}, },
grid: { grid: {
color: surfaceBorder, color: surfaceBorder,
drawBorder: false drawBorder: false,
display: true
} }
}, },
y: { y: {