|
App.component.html:
// add your additional code here <ejs-stockchart id='stockChartDefault' (load)='load($event)'>
<e-stockchart-series-collection> <e-stockchart-series [dataSource]='data1' type='Candle' xName='date' yName='high' high='high' low='low'> </e-stockchart-series> </e-stockchart-series-collection> </ejs-stockchart>
App.component.ts: import { Component, ViewEncapsulation} from '@angular/core';
import { IStockChartEventArgs } from '@syncfusion/ej2-angular-charts'; import datasource from './datasource.json'; @Component({ selector: 'app-root', templateUrl: 'app.component.html', encapsulation: ViewEncapsulation.None }) export class AppComponent { public data1: Object[] = datasource; // add your additional code here public load(args: IStockChartEventArgs): void { for( var i = 0; i < args.stockChart.series[0].dataSource.length; i++) { args.stockChart.series[0].dataSource[i].date = new Date(args.stockChart.series[0].dataSource[i].date); }; }; }
datasource.json:
[
{ "date": "2012-04-02", "open" : 85.9757, "high": 90.6657, "low" : 85.7685, "close" : 90.5257, "volume" : 660187068 }, { "date": "2012-04-09", "open" : 89.4471, "high": 92, "low" : 86.2157, "close" : 86.4614, "volume" : 912634864 }, { "date": "2012-04-16", "open" : 87.1514, "high": 88.6071, "low" : 81.4885, "close" : 81.8543, "volume" : 1221746066 }, { "date": "2012-04-23", "open" : 81.5157, "high": 88.2857, "low" : 79.2857, "close" : 86.1428, "volume" : 965935749 }, { "date": "2012-04-30", "open" : 85.4, "high": 85.4857, "low" : 80.7385, "close" : 80.75, "volume" : 615249365 }, { "date": "2012-05-07", "open" : 80.2143, "high": 82.2685, "low" : 79.8185, "close" : 80.9585, "volume" : 541742692 }, { "date": "2012-05-14", "open" : 80.3671, "high": 81.0728, "low" : 74.5971, "close" : 75.7685, "volume" : 708126233 }, { "date": "2012-05-21", "open" : 76.3571, "high": 82.3571, "low" : 76.2928, "close" : 80.3271, "volume" : 682076215 }, { "date": "2012-05-28", "open" : 81.5571, "high": 83.0714, "low" : 80.0743, "close" : 80.1414, "volume" : 480059584 } ] |
|
App.component.html:
// add your additional code here <ejs-stockchart id='stockChartDefault' [primaryXAxis]='primaryXAxis' style="display:block;">
<e-stockchart-series-collection>
<e-stockchart-series [dataSource]='stockchartData' type='Candle' xName='date' yName='high' high='high' low='low'>
</e-stockchart-series>
</e-stockchart-series-collection> </ejs-stockchart>App.component.ts: import { Component, ViewEncapsulation} from '@angular/core';
import { IStockChartEventArgs } from '@syncfusion/ej2-angular-charts'; import { HeroService } from './hero.service' @Component({ selector: 'app-root', templateUrl: 'app.component.html', encapsulation: ViewEncapsulation.None }) export class AppComponent { // add your additional code here
ngOnInit(): void {
this.getData();
// add your additional code here
}
getData() {
this.service.getCompanyDetailsData()
.subscribe(
(data)=> { this.stockchartData = data },
err => console.error(err),
() => console.log('done')
);
} constructor(private service: HeroService) {}}
Hero.service.ts:
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable, throwError } from 'rxjs';
import { catchError, retry, map } from 'rxjs/operators';
@Injectable({
providedIn: 'root',
})
export class HeroService {
constructor(public http: HttpClient) {}
getCompanyDetailsData(): Observable<any[]> {
const data : Observable<any[]> = this.http.get<any[]>('assets/data/company-details-mock-data.json').pipe(
map((res) => res.map(item => this.formatDates(item)))
);
return data;
}
formatDates(results) {
results.date = new Date(results.date)
return results;
} }company-details-mock-data.json:
[
{ "date": "2012-04-02", "open" : 85.9757, "high": 90.6657, "low" : 85.7685, "close" : 90.5257, "volume" : 660187068 }, { "date": "2012-04-09", "open" : 89.4471, "high": 92, "low" : 86.2157, "close" : 86.4614, "volume" : 912634864 }, { "date": "2012-04-16", "open" : 87.1514, "high": 88.6071, "low" : 81.4885, "close" : 81.8543, "volume" : 1221746066 }, { "date": "2012-04-23", "open" : 81.5157, "high": 88.2857, "low" : 79.2857, "close" : 86.1428, "volume" : 965935749 }, { "date": "2012-04-30", "open" : 85.4, "high": 85.4857, "low" : 80.7385, "close" : 80.75, "volume" : 615249365 }, { "date": "2012-05-07", "open" : 80.2143, "high": 82.2685, "low" : 79.8185, "close" : 80.9585, "volume" : 541742692 }, { "date": "2012-05-14", "open" : 80.3671, "high": 81.0728, "low" : 74.5971, "close" : 75.7685, "volume" : 708126233 }, { "date": "2012-05-21", "open" : 76.3571, "high": 82.3571, "low" : 76.2928, "close" : 80.3271, "volume" : 682076215 }, { "date": "2012-05-28", "open" : 81.5571, "high": 83.0714, "low" : 80.0743, "close" : 80.1414, "volume" : 480059584 } ] |