Search results

Internationalization in Angular Stock Chart component

17 Sep 2021 / 2 minutes to read

Chart provide supports for internationalization for below chart elements.

  • Axis label.
  • Tooltip.
  • Crosshair

For more information about number and date formatter you can refer internationalization.

Globalization

Globalization is the process of designing and developing an component that works in different cultures/locales. Internationalization library is used to globalize number, date, time values in Chart component using labelFormat property in axis.

Numeric Format

In the below example axis labels, tooltip and crosshair labels are globalized to EUR.

Source
Preview
app.component.ts
app.module.ts
main.ts
Copied to clipboard
import { Component, ViewEncapsulation, OnInit } from '@angular/core';
import { chartData } from 'datasource.ts';
import { setCurrencyCode, L10n, setCulture  } from '@syncfusion/ej2-base';
setCurrencyCode("EUR");

@Component({
selector: 'app-container',
template:
    `<ejs-stockchart id='chart-container' [primaryXAxis]='primaryXAxis' style="display:block;"
    [primaryYAxis]='primaryYAxis' [crosshair]='crosshair' (tooltipRender)='tooltipRender($event)' [tooltip]='tooltip'>
    <e-stockchart-series-collection>
        <e-stockchart-series [dataSource]='data1' type='Candle' xName='x' yName='high' high='high' low='low'>
        </e-stockchart-series>
    </e-stockchart-series-collection>
</ejs-stockchart>`
})

export class AppComponent implements OnInit {

public data1: Object[] = chartData;

public primaryXAxis: Object = { majorGridLines: { color: 'transparent' }, crosshairTooltip: { enable: true } };

public primaryYAxis: Object = {
    lineStyle: { color: 'transparent' },
    majorTickLines: { color: 'transparent', width: 0 },
    labelFormat: 'c',
    crosshairTooltip: { enable: true }
};
public crosshair: Object = {
    enable: true
};
public tooltipRender(args: ITooltipRenderEventArgs): void {
    if (args.text.split('<br/>')[4]) {
    let target: number = parseInt(args.text.split('<br/>')[4].split('<b>')[1].split('</b>')[0], 10);
    let value: string = (target / 100000000).toFixed(1) + 'B';
    args.text = args.text.replace(args.text.split('<br/>')[4].split('<b>')[1].split('</b>')[0], value);
    }
};

public tooltip: object = { enable: true };
constructor() {
    //code
}
}
Copied to clipboard
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import { ChartAllModule, StockChartAllModule } from '@syncfusion/ej2-angular-charts';
import { CandleSeriesService, LineSeriesService, TmaIndicatorService, DateTimeService} from '@syncfusion/ej2-angular-charts';

/**
 * Module
 */
@NgModule({
    imports: [
        BrowserModule, ChartAllModule, StockChartAllModule
    ],
    declarations: [AppComponent],
    bootstrap: [AppComponent],
    providers: [ CandleSeriesService, LineSeriesService, TmaIndicatorService, DateTimeService]
})
export class AppModule { }
Copied to clipboard
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { enableProdMode } from '@angular/core';
import { AppModule } from './app.module';

enableProdMode();
platformBrowserDynamic().bootstrapModule(AppModule);