Fix invalid graph errors + no data errors

This commit is contained in:
Ben Goldsworthy 2020-11-29 16:29:06 +00:00
parent 5911c4d8ee
commit 2aa42fa291
5 changed files with 34 additions and 27 deletions

View file

@ -10,7 +10,7 @@
</widget-graph> </widget-graph>
</div><!--/.col--> </div><!--/.col-->
</div><!--/.row--> </div><!--/.row-->
<div class=row> <div *ngIf="showEssentialBarChart" class=row>
<div class="col-xl-6"> <div class="col-xl-6">
<panel-pie></panel-pie><!--All Purchases --> <panel-pie></panel-pie><!--All Purchases -->
<!-- <div class="demo-container" ng-app="stacked-bar" ng-controller="stacked-bar"> <!-- <div class="demo-container" ng-app="stacked-bar" ng-controller="stacked-bar">
@ -40,7 +40,7 @@
</div> --> </div> -->
<!-- </body> --> <!-- </body> -->
<!-- </div> --><!--/.col--> <!-- </div> --><!--/.col-->
<div *ngIf="showEssentialBarChart" class="col-xl-6"> <div class="col-xl-6">
<div class="card"> <div class="card">
<div class="card-block"> <div class="card-block">
<div class="row"> <div class="row">
@ -82,15 +82,15 @@
</div> </div>
</div> </div>
</div><!--/.col--> </div><!--/.col-->
<div class="col-xl-6"> <div *ngIf="showTotalCategoryList" class="col-xl-6">
<div class="card"> <div class="card">
<div class="card-block"> <div class="card-block">
<div class="row"> <div lass="row">
<div class="col-12"> <div class="col-12">
<h4 class="card-title float-left mb-0"> Global Puchases by Category</h4> <h4 class="card-title float-left mb-0"> Global Puchases by Category</h4>
</div> </div>
<div class="col-12"> <div class="col-12">
<div *ngIf="showTotalCategoryList" class="chart-wrapper"> <div class="chart-wrapper">
<ul class="icons-list"> <ul class="icons-list">
<!-- New loop --> <!-- New loop -->
<li *ngFor="let category of totalCategoryList | slice:0:totalCategoryLimit; let i=index"> <li *ngFor="let category of totalCategoryList | slice:0:totalCategoryLimit; let i=index">

View file

@ -9,7 +9,7 @@ import { CustBarSnippetComponent } from '../snippets/cust-snippet-bar.component'
import { PiePanel } from '../panels/pie-panel.component'; import { PiePanel } from '../panels/pie-panel.component';
import { DataType } from '../shared/data-types.enum'; import { DataType } from '../shared/data-types.enum';
import * as moment from 'moment'; import * as moment from 'moment';
import { MoreStuffComponent } from '../dashboard/more-graphs-and-tables.component'; //import { MoreStuffComponent } from '../dashboard/more-graphs-and-tables.component';
// import { StackedBarChartComponent } from '../panels/stacked-bar.component'; // import { StackedBarChartComponent } from '../panels/stacked-bar.component';
interface SuppliersComponent { interface SuppliersComponent {
@ -186,20 +186,22 @@ export class DashboardCustomerComponent implements OnInit {
this.setDate(); this.setDate();
this.api.customerStats().subscribe( this.api.customerStats().subscribe(
result => { result => {
this.setWeekPurchaseList(result.weeks); if (result.data.cat_list.length > 0) {
this.setWeekData(result); this.setWeekPurchaseList(result.weeks);
this.setChartData(result.data.cat_total); this.setWeekData(result);
this.totalCategoryList = result.data.cat_list; this.setChartData(result.data.cat_total);
if (this.totalCategoryList) { this.totalCategoryList = result.data.cat_list;
this.showTotalCategoryList = true; if (this.totalCategoryList) {
this.showTotalCategoryList = true;
}
this.purchaseEssential = result.data.essentials.purchase_no_essential_total;
this.purchaseNotEssential = result.data.essentials.purchase_no_total - this.purchaseEssential;
this.barChartDataEssential = [
{data: [this.purchaseEssential], label: 'Essential', stack: '1'},
{data: [this.purchaseNotEssential], label: 'Non-Essential', stack: '1'},
];
this.showEssentialBarChart = true;
} }
this.purchaseEssential = result.data.essentials.purchase_no_essential_total;
this.purchaseNotEssential = result.data.essentials.purchase_no_total - this.purchaseEssential;
this.barChartDataEssential = [
{data: [this.purchaseEssential], label: 'Essential', stack: '1'},
{data: [this.purchaseNotEssential], label: 'Non-Essential', stack: '1'},
];
this.showEssentialBarChart = true;
}, },
error => { error => {
console.log('Retrieval Error'); console.log('Retrieval Error');

View file

@ -13,7 +13,7 @@
</div><!--/.row--> </div><!--/.row-->
<panel-graph></panel-graph> <panel-graph></panel-graph>
<div class=row> <div class=row>
<div class="col-xl-6"> <div *ngIf="showEssentialBarChart" class="col-xl-6">
<div class="card"> <div class="card">
<div class="card-block"> <div class="card-block">
<div class="row"> <div class="row">
@ -21,7 +21,7 @@
<h4 class="card-title mb-0">Number of Essential Purchases</h4> <h4 class="card-title mb-0">Number of Essential Purchases</h4>
</div> </div>
</div> </div>
<div *ngIf="showEssentialBarChart" class="chart-wrapper"> <div class="chart-wrapper">
<canvas baseChart class="chart" <canvas baseChart class="chart"
[datasets]="barChartDataEssential" [datasets]="barChartDataEssential"
[labels]="barChartLabelsEssential" [labels]="barChartLabelsEssential"
@ -33,7 +33,7 @@
</div> </div>
</div> </div>
</div><!--/.col--> </div><!--/.col-->
<div class="col-xl-6"> <div *ngIf="showEssentialBarChart" class="col-xl-6">
<div class="card"> <div class="card">
<div class="card-block"> <div class="card-block">
<div class="row"> <div class="row">
@ -80,7 +80,7 @@
<div class="col-xl-6"> <div class="col-xl-6">
<org-pie-panel></org-pie-panel> <org-pie-panel></org-pie-panel>
</div> </div>
<div class="col-xl-6"> <div *ngIf="showTotalCategoryList" class="col-xl-6">
<div class="card"> <div class="card">
<div class="card-block"> <div class="card-block">
<div class="row"> <div class="row">
@ -88,7 +88,7 @@
<h4 class="card-title float-left mb-0"> Global Puchases by Category</h4> <h4 class="card-title float-left mb-0"> Global Puchases by Category</h4>
</div> </div>
<div class="col-12"> <div class="col-12">
<div *ngIf="showTotalCategoryList" class="chart-wrapper"> <div class="chart-wrapper">
<ul class="icons-list"> <ul class="icons-list">
<!-- New loop --> <!-- New loop -->
<li *ngFor="let category of totalCategoryList | slice:0:totalCategoryLimit; let i=index"> <li *ngFor="let category of totalCategoryList | slice:0:totalCategoryLimit; let i=index">

View file

@ -44,6 +44,7 @@ export class DashboardComponent {
title: 'Sales Last 30 Days', title: 'Sales Last 30 Days',
dataType: DataType.currency, dataType: DataType.currency,
}, },
/* Not implemented on server
{ {
type: 'graph', type: 'graph',
name: 'sales_last_quart', name: 'sales_last_quart',
@ -51,6 +52,7 @@ export class DashboardComponent {
title: 'Sales Last Quart', title: 'Sales Last Quart',
dataType: DataType.currency, dataType: DataType.currency,
}, },
*/
{ {
type: 'graph', type: 'graph',
name: 'purchases_last_7_days', name: 'purchases_last_7_days',
@ -63,12 +65,14 @@ export class DashboardComponent {
title: 'Purchases Last 30 Days', title: 'Purchases Last 30 Days',
dataType: DataType.currency, dataType: DataType.currency,
}, },
/* Not implemented on server
{ {
type: 'graph', type: 'graph',
name: 'purchases_last_quart;', name: 'purchases_last_quart;',
title: 'Purchases Last Quart', title: 'Purchases Last Quart',
dataType: DataType.currency, dataType: DataType.currency,
}, },
*/
]; ];
disableCategoryButton: boolean = false; disableCategoryButton: boolean = false;
@ -286,7 +290,6 @@ export class DashboardComponent {
{data: [this.purchaseNotEssential], label: 'Non-Essential', stack: '1'}, {data: [this.purchaseNotEssential], label: 'Non-Essential', stack: '1'},
]; ];
this.showEssentialBarChart = true; this.showEssentialBarChart = true;
console.log(this.barChartDataEssential);
} }
private setChartDataCat(dataCat: any) { private setChartDataCat(dataCat: any) {

View file

@ -109,8 +109,10 @@ export class GraphWidget implements OnInit {
if ( !( this.dataType in DataType ) ) { if ( !( this.dataType in DataType ) ) {
console.warn('Unknown DataType for graph \'' + this.graphName + '\' - defaulting to number'); console.warn('Unknown DataType for graph \'' + this.graphName + '\' - defaulting to number');
} }
this.graphService.getGraph(this.graphName) if (localStorage.getItem('usertype') === 'organisation') {
.subscribe( result => this.setData(result.graph) ); this.graphService.getGraph(this.graphName)
.subscribe( result => this.setData(result.graph) );
}
} }
private setData(data: any) { private setData(data: any) {