import { Component, ViewChild, ElementRef } from '@angular/core';
import { jqxChartComponent } from 'jqwidgets-scripts/jqwidgets-ts/angular_jqxchart';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
})
export class AppComponent {
@ViewChild('myChart') myChart: jqxChartComponent;
@ViewChild('eventsText') eventsText: ElementRef;
months: string[] = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
getWidth() : any {
if (document.body.offsetWidth < 850) {
return '90%';
}
return 850;
}
source: any =
{
datatype: 'tsv',
datafields: [
{ name: 'Date' },
{ name: 'SPOpen' },
{ name: 'SPHigh' },
{ name: 'SPLow' },
{ name: 'SPClose' },
{ name: 'SPVolume' },
{ name: 'SPAdjClose' }
],
url: '../assets/nasdaq_vs_sp500_detailed.txt'
};
dataAdapter: any = new jqx.dataAdapter(this.source, { async: false, autoBind: true, loadError: (xhr: any, status: any, error: any) => { alert('Error loading "' + this.source.url + '" : ' + error); } });
padding: any = { left: 20, top: 5, right: 20, bottom: 5 };
xAxis: any =
{
dataField: 'Date',
type: 'date',
valuesOnTicks: true,
minValue: new Date(2014, 1, 1),
maxValue: new Date(2014, 10, 1),
labels:
{
formatFunction: (value: any) => {
return value.getDate() + '-' + this.months[value.getMonth()] + '
' + value.getFullYear().toString();
}
},
gridLines: { visible: false },
rangeSelector: {
size: 100,
padding: { top: 10, bottom: 0 },
backgroundColor: 'white',
dataField: 'SPClose',
baseUnit: 'month',
showGridLines: false,
formatFunction: (value: any) => {
return this.months[value.getMonth()] + '\'' + value.getFullYear().toString().substring(2);
}
}
};
toolTipCustomFormatFn = (value: any, itemIndex: any, serie: any, group: any, categoryValue: any, categoryAxis: any) => {
let dataItem = this.dataAdapter.records[itemIndex];
let volume = dataItem.SPVolume;
return '