Skip to content

Commit

Permalink
UI Charts using High Charts API
Browse files Browse the repository at this point in the history
  • Loading branch information
kdsalvy committed Jun 15, 2020
1 parent c6a948d commit 5679620
Show file tree
Hide file tree
Showing 11 changed files with 133 additions and 12 deletions.
5 changes: 5 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"@angular/platform-browser-dynamic": "~8.2.13",
"@angular/router": "^8.2.14",
"bootstrap": "^4.3.1",
"highcharts": "^8.1.1",
"rxjs": "~6.4.0",
"rxjs-compat": "^6.5.3",
"tslib": "^1.10.0",
Expand Down
8 changes: 7 additions & 1 deletion src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { HomeComponent } from './home/home.component';
import { GithubProfileComponent } from './github-profile/github-profile.component';
import { GridComponent } from './grid/grid.component';
import { GridService } from './services/grid.service';
import { ChartsComponent } from './charts/charts.component';

@NgModule({
declarations: [
Expand All @@ -51,7 +52,8 @@ import { GridService } from './services/grid.service';
NavbarComponent,
HomeComponent,
GithubProfileComponent,
GridComponent
GridComponent,
ChartsComponent
],
imports: [
BrowserModule,
Expand Down Expand Up @@ -93,6 +95,10 @@ import { GridService } from './services/grid.service';
path: 'grid',
component: GridComponent
},
{
path: 'chart',
component: ChartsComponent
},
{
path: '**',
redirectTo: ''
Expand Down
Empty file.
1 change: 1 addition & 0 deletions src/app/charts/charts.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<div id="container"></div>
25 changes: 25 additions & 0 deletions src/app/charts/charts.component.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';

import { ChartsComponent } from './charts.component';

describe('ChartsComponent', () => {
let component: ChartsComponent;
let fixture: ComponentFixture<ChartsComponent>;

beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ ChartsComponent ]
})
.compileComponents();
}));

beforeEach(() => {
fixture = TestBed.createComponent(ChartsComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
78 changes: 78 additions & 0 deletions src/app/charts/charts.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import { Component, OnInit } from '@angular/core';
import * as Highcharts from 'highcharts';

declare var require: any;
let Boost = require('highcharts/modules/boost');
let noData = require('highcharts/modules/no-data-to-display');
let More = require('highcharts/highcharts-more');

Boost(Highcharts);
noData(Highcharts);
More(Highcharts);
noData(Highcharts);

@Component({
selector: 'app-charts',
templateUrl: './charts.component.html',
styleUrls: ['./charts.component.css']
})
export class ChartsComponent implements OnInit {

public options: any = {
chart: {
type: 'line',
height: 700
},
title: {
text: 'Sample Line Plot'
},
credits: {
enabled: false
},
tooltip: {
formatter: function() {
return 'x: ' + Highcharts.dateFormat('%e %b %y %H:%M:%S', this.x) +
' y: ' + this.y.toFixed(2) +
' data: ' + this.point.options.extraData;
}
},
xAxis: {
type: 'datetime',
labels: {
formatter: function() {
return Highcharts.dateFormat('%e %b %y', this.value);
}
}
},
series: [
{
name: 'Normal',
turboThreshold: 500000,
data: [
{'x': new Date('2018-01-25 18:38:31').getTime(), 'y': 2, 'extraData': 1},
{'x': new Date('2018-01-26 20:38:31').getTime(), 'y': 5, 'extraData': 2},
{'x': new Date('2018-01-27 15:38:31').getTime(), 'y': 3, 'extraData': 3},
{'x': new Date('2018-01-28 17:38:31').getTime(), 'y': 2, 'extraData': 4},
{'x': new Date('2018-01-29 14:38:31').getTime(), 'y': 3, 'extraData': 5},
],
extraData: [
1,2,3,4,5
]
},
{
name: 'Abnormal',
turboThreshold: 500000,
data: [
{'x': new Date('2018-01-25 18:38:31').getTime(), 'y': 6, 'extraData': 1},
{'x': new Date('2018-01-26 18:38:31').getTime(), 'y': 5, 'extraData': 2},
{'x': new Date('2018-02-01 18:38:31').getTime(), 'y': 7, 'extraData': 3}
]
}
]
}
constructor() { }

ngOnInit(){
Highcharts.chart('container', this.options);
}
}
5 changes: 3 additions & 2 deletions src/app/grid/grid.component.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.ag-theme-balham .ag-header-group-cell-label span {
float: right;
.ag-theme-balham .ag-body-viewport {
overflow-y: hidden !important;
overflow-x: hidden !important;
}
4 changes: 2 additions & 2 deletions src/app/grid/grid.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
[autoGroupColumnDef]="autoGroupColumnDef"
>
</ag-grid-angular> -->

<ag-grid-angular
#agGrid
style="width: 1200px; height: 500px;"
class="ag-theme-balham"
[colWidth]=100
[rowData]="rowData | async"
[columnDefs]="columnDefs"
[modules]="modules"
rowSelection="multiple"
>
</ag-grid-angular>
</ag-grid-angular>
17 changes: 10 additions & 7 deletions src/app/grid/grid.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,17 @@ export class GridComponent implements OnInit {
@ViewChild('agGrid', { static: true}) agGrid: AgGridAngular;

columnDefs = [
{headerName: 'Make', field: 'make', sortable: true, filter: true, checkboxSelection: true },
{headerName: 'Model', field: 'model', sortable: true, filter: true },
{headerName: 'Price', field: 'price', sortable: true, filter: true },
{headerName: 'Make', field: 'make', sortable: true, filter: true, checkboxSelection: true, suppressSizeToFit: true},
{headerName: 'Model', field: 'model', sortable: true, filter: true, suppressSizeToFit: true},
{headerName: 'Price', field: 'price', sortable: true, filter: true, suppressSizeToFit: true},
{headerName: 'Price', children: [
{headerName: 'Make', field: 'make', sortable: true, filter: true},
{headerName: 'Model', field: 'model', sortable: true, filter: true },
{headerName: 'Price', field: 'price', sortable: true, filter: true }
]}
{headerName: 'Make', field: 'make', sortable: true, filter: true, suppressSizeToFit: true},
{headerName: 'Model', field: 'model', sortable: true, filter: true, suppressSizeToFit: true},
{headerName: 'Price', field: 'price', sortable: true, filter: true, suppressSizeToFit: true}
], width: '25%'},
{headerName: 'Make', field: 'make', sortable: true, filter: true, checkboxSelection: true, suppressSizeToFit: true},
{headerName: 'Model', field: 'model', sortable: true, filter: true, suppressSizeToFit: true},
{headerName: 'Price', field: 'price', sortable: true, filter: true, suppressSizeToFit: true}
];

// rowData = [
Expand Down
1 change: 1 addition & 0 deletions src/app/navbar/navbar.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<li routerLinkActive="nav-item active"><a class="nav-link" routerLink="/template-form">Template-Driven Form</a></li>
<li routerLinkActive="nav-item active"><a class="nav-link" routerLink="/reactive-form">Reactive Form</a></li>
<li routerLinkActive="nav-item active"><a class="nav-link" routerLink="/grid">Grid</a></li>
<li routerLinkActive="nav-item active"><a class="nav-link" routerLink="/chart">Charts</a></li>
</ul>
</div>
</div>
Expand Down

0 comments on commit 5679620

Please sign in to comment.