Added working snippets and placeholder pie chart
This commit is contained in:
parent
6eb6425fb8
commit
32bebd7c24
9 changed files with 142 additions and 41 deletions
27
src/app/panels/pie-panel.component.html
Normal file
27
src/app/panels/pie-panel.component.html
Normal file
|
@ -0,0 +1,27 @@
|
|||
<div class="card">
|
||||
<div class="card-block">
|
||||
<div class="row">
|
||||
<div class="col-sm-5">
|
||||
<h4 class="card-title mb-0">Local Purchases</h4>
|
||||
</div><!--/.col-->
|
||||
<div class="col-sm-7 hidden-sm-down">
|
||||
<div class="btn-toolbar float-right" role="toolbar" aria-label="Toolbar with button groups">
|
||||
<div class="btn-group mr-3" data-toggle="buttons" aria-label="First group">
|
||||
<label class="btn btn-outline-secondary active">
|
||||
<input type="radio" name="options" id="option2" checked> Week
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
</div><!--/.col-->
|
||||
</div><!--/.row-->
|
||||
<div class="chart-wrapper">
|
||||
<canvas baseChart class="chart"
|
||||
[data]="placeholderChartData"
|
||||
[labels]="placeholderChartLabels"
|
||||
[legend]="chartLegend"
|
||||
[chartType]="chartType"
|
||||
(chartHover)="chartHovered($event)"
|
||||
(chartClick)="chartClicked($event)"></canvas>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
85
src/app/panels/pie-panel.component.ts
Normal file
85
src/app/panels/pie-panel.component.ts
Normal file
|
@ -0,0 +1,85 @@
|
|||
import { Component, OnInit, Input, Output, EventEmitter } from '@angular/core';
|
||||
import { OrgGraphsService } from '../providers/org-graphs.service';
|
||||
import { DataType } from '../shared/data-types.enum';
|
||||
import { ChartData } from '../_interfaces/chart-data';
|
||||
import * as moment from 'moment';
|
||||
|
||||
@Component({
|
||||
selector: 'panel-pie',
|
||||
templateUrl: 'pie-panel.component.html',
|
||||
})
|
||||
export class PiePanel implements OnInit {
|
||||
|
||||
// Placeholder
|
||||
public placeholderChartLabels: string[] = ['Local to Me', 'Local Store', 'Not Local'];
|
||||
public placeholderChartData: number[] = [400, 100, 100];
|
||||
|
||||
|
||||
public chartType = 'doughnut';
|
||||
public chartLegend = true;
|
||||
|
||||
//Old
|
||||
|
||||
public rawChartData: Array<number> = [];
|
||||
|
||||
public chartData: Array<ChartData> = [
|
||||
{
|
||||
data: [],
|
||||
label: 'This Week'
|
||||
},
|
||||
{
|
||||
data: [],
|
||||
label: 'Last Week'
|
||||
},
|
||||
{
|
||||
data: [],
|
||||
label: 'Week Before Last'
|
||||
}
|
||||
];
|
||||
|
||||
public rawChartLabels: Array<string> = [];
|
||||
public chartLabels: Array<string> = [];
|
||||
|
||||
// public mainChartElements = 7;
|
||||
|
||||
constructor(
|
||||
private graphService: OrgGraphsService,
|
||||
) { }
|
||||
|
||||
public ngOnInit(): void {
|
||||
// const end = moment().startOf('day');
|
||||
// const start = end.clone().subtract(this.mainChartElements * 3, 'days');
|
||||
// this.graphService.getGraph('customers_range', {
|
||||
// start: start.format('YYYY-MM-DD'),
|
||||
// end: end.format('YYYY-MM-DD'),
|
||||
// }).subscribe( result => this.setData(result.graph) );
|
||||
}
|
||||
|
||||
// private setData(data: any) {
|
||||
// this.chartLabels = data.labels.slice(this.mainChartElements * 2, this.mainChartElements * 3);
|
||||
// this.chartData[2].data = data.data.slice(0, this.mainChartElements);
|
||||
// this.chartData[1].data = data.data.slice(this.mainChartElements, this.mainChartElements * 2);
|
||||
// this.chartData[0].data = data.data.slice(this.mainChartElements * 2, this.mainChartElements * 3);
|
||||
// }
|
||||
|
||||
// convert Hex to RGBA
|
||||
public convertHex(hex: string, opacity: number) {
|
||||
hex = hex.replace('#', '');
|
||||
const r = parseInt(hex.substring(0, 2), 16);
|
||||
const g = parseInt(hex.substring(2, 4), 16);
|
||||
const b = parseInt(hex.substring(4, 6), 16);
|
||||
|
||||
const rgba = 'rgba(' + r + ', ' + g + ', ' + b + ', ' + opacity / 100 + ')';
|
||||
return rgba;
|
||||
}
|
||||
|
||||
// events
|
||||
public chartClicked(e: any): void {
|
||||
console.log(e);
|
||||
}
|
||||
|
||||
public chartHovered(e: any): void {
|
||||
console.log(e);
|
||||
}
|
||||
|
||||
}
|
Reference in a new issue