Financial types in React Chart component
20 Jan 202322 minutes to read
Financial charts are used to illustrate the movements in the price of a financial instrument over time.
To get start quickly with React Financial Charts, you can check on this video:
Chart supports the following financial series
Hilo
To render a Hilo series, use series type
as Hilo
and inject HiloSeries
module into the services
.
import * as React from "react";
import * as ReactDOM from "react-dom";
import { ChartComponent, SeriesCollectionDirective, SeriesDirective, Inject, HiloSeries, Category, Tooltip, Zoom, Crosshair } from '@syncfusion/ej2-react-charts';
import { chartData } from './datasource';
function App() {
const primaryxAxis = { valueType: 'Category', title: 'Months' };
const primaryyAxis = { labelFormat: '{value}mm', edgeLabelPlacement: 'Shift', title: 'Rainfall' };
const style = { textAlign: "center" };
const legendSettings = { visible: false };
return <ChartComponent id='charts' style={style} primaryXAxis={primaryxAxis} primaryYAxis={primaryyAxis} legendSettings={legendSettings} title='Maximum and Minimum Rainfall'>
<Inject services={[HiloSeries, Tooltip, Category, Crosshair, Zoom]}/>
<SeriesCollectionDirective>
<SeriesDirective dataSource={chartData} xName='x' yName='low' name='India' type='Hilo' low='low' high='high'>
</SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>;
}
;
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));
import * as React from "react";
import * as ReactDOM from "react-dom";
import { AxisModel, ChartComponent, SeriesCollectionDirective, SeriesDirective, Inject,LegendSettingsModel,
HiloSeries, Category, Tooltip, ILoadedEventArgs, Zoom,
Crosshair, ChartTheme }
from'@syncfusion/ej2-react-charts';
import { chartData } from './datasource';
function App() {
const primaryxAxis: AxisModel = { valueType: 'Category', title: 'Months' };
const primaryyAxis: AxisModel = { labelFormat: '{value}mm', edgeLabelPlacement: 'Shift', title: 'Rainfall' };
const style: any = { textAlign: "center" };
const legendSettings: LegendSettingsModel = { visible: false };
return <ChartComponent id='charts' style={style}
primaryXAxis={primaryxAxis}
primaryYAxis={primaryyAxis}
legendSettings={legendSettings}
title='Maximum and Minimum Rainfall'>
<Inject services={[HiloSeries, Tooltip, Category, Crosshair, Zoom]} />
<SeriesCollectionDirective>
<SeriesDirective dataSource={chartData} xName='x' yName='low' name='India' type='Hilo' low='low'
high='high'>
</SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>
};
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));
High Low Open Close
To render a HiloOpenClose series, use series type
as HiloOpenClose
and inject HiloOpenCloseSeries
module into the services
.
import * as React from "react";
import * as ReactDOM from "react-dom";
import { ChartComponent, SeriesCollectionDirective, SeriesDirective, Inject, Category, Tooltip, Zoom, Crosshair, HiloOpenCloseSeries } from '@syncfusion/ej2-react-charts';
import { Browser } from '@syncfusion/ej2-base';
import { chartData } from './datasource';
function App() {
const primaryxAxis = { title: 'Date', valueType: 'Category' };
const primaryyAxis = { title: 'Price in Dollar', minimum: 100, maximum: 200, interval: 20 };
const style = { textAlign: "center" };
const legendSettings = { visible: false };
const border = { border: { width: 0 } };
return <ChartComponent id='charts' style={style} primaryXAxis={primaryxAxis} primaryYAxis={primaryyAxis} legendSettings={legendSettings} chartArea={border} width={Browser.isDevice ? '100%' : '80%'} title='Financial Analysis'>
<Inject services={[HiloOpenCloseSeries, Tooltip, Category, Crosshair, Zoom]}/>
<SeriesCollectionDirective>
<SeriesDirective dataSource={chartData} xName='x' yName='low' name='SHIRPUR-G' type='HiloOpenClose' low='low' high='high' open='open' close='close'>
</SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>;
}
;
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));
import * as React from "react";
import * as ReactDOM from "react-dom";
import { AxisModel, ChartComponent, SeriesCollectionDirective, SeriesDirective, Inject,LegendSettingsModel,
Legend, Category, Tooltip, DataLabel, Zoom, Crosshair, HiloOpenCloseSeries, Selection}
from'@syncfusion/ej2-react-charts';
import { Browser } from '@syncfusion/ej2-base';
import { chartData } from './datasource';
function App() {
const primaryxAxis: AxisModel = { title: 'Date', valueType: 'Category' };
const primaryyAxis: AxisModel = { title: 'Price in Dollar', minimum: 100, maximum: 200, interval: 20 };
const style: any = { textAlign: "center" };
const legendSettings: LegendSettingsModel = { visible: false };
const border = { border: { width: 0 } };
return <ChartComponent id='charts' style={style}
primaryXAxis={primaryxAxis}
primaryYAxis={primaryyAxis}
legendSettings={legendSettings}
chartArea={border}
width={Browser.isDevice ? '100%' : '80%'}
title='Financial Analysis'>
<Inject services={[HiloOpenCloseSeries, Tooltip, Category, Crosshair, Zoom]} />
<SeriesCollectionDirective>
<SeriesDirective dataSource={chartData} xName='x' yName='low' name='SHIRPUR-G' type='HiloOpenClose' low='low'
high='high' open='open' close='close'>
</SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>
};
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));
Customization of HiloOpenClose Series
In HiloOpenClose series, bullFillColor
is used to fill the segment when the open value is greater than the close value and bearFillColor
is used to fill the segment when the open value is less than the close value.
import * as React from "react";
import * as ReactDOM from "react-dom";
import { ChartComponent, SeriesCollectionDirective, SeriesDirective, Inject, Category, Tooltip, Zoom, Crosshair, HiloOpenCloseSeries } from '@syncfusion/ej2-react-charts';
import { chartData } from './datasource';
function App() {
const primaryxAxis = { title: 'Date', valueType: 'Category' };
const primaryyAxis = { title: 'Price in Dollar', minimum: 100, maximum: 200, interval: 20 };
const style = { textAlign: "center" };
const legendSettings = { visible: false };
return <ChartComponent id='charts' style={style} primaryXAxis={primaryxAxis} primaryYAxis={primaryyAxis} legendSettings={legendSettings} title='Financial Analysis'>
<Inject services={[HiloOpenCloseSeries, Tooltip, Category, Crosshair, Zoom]}/>
<SeriesCollectionDirective>
<SeriesDirective dataSource={chartData} xName='x' yName='low' name='SHIRPUR-G' type='HiloOpenClose' low='low' high='high' open='open' close='close' bearFillColor='#e56590' bullFillColor='#f8b883'>
</SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>;
}
;
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));
import * as React from "react";
import * as ReactDOM from "react-dom";
import { AxisModel, ChartComponent, SeriesCollectionDirective, SeriesDirective, Inject,LegendSettingsModel,
Legend, Category, Tooltip, DataLabel, Zoom, Crosshair, HiloOpenCloseSeries, Selection}
from'@syncfusion/ej2-react-charts';
import { chartData } from './datasource';
function App() {
const primaryxAxis: AxisModel = { title: 'Date', valueType: 'Category' };
const primaryyAxis: AxisModel = { title: 'Price in Dollar', minimum: 100, maximum: 200, interval: 20 };
const style: any = { textAlign: "center" };
const legendSettings: LegendSettingsModel = { visible: false };
return <ChartComponent id='charts' style={style}
primaryXAxis={primaryxAxis}
primaryYAxis={primaryyAxis}
legendSettings={legendSettings}
title='Financial Analysis'>
<Inject services={[HiloOpenCloseSeries, Tooltip, Category, Crosshair, Zoom]} />
<SeriesCollectionDirective>
<SeriesDirective dataSource={chartData} xName='x' yName='low' name='SHIRPUR-G' type='HiloOpenClose' low='low'
high='high' open='open' close='close' bearFillColor='#e56590' bullFillColor='#f8b883'>
</SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>
};
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));
Candle
To render a Candle series, use series type
as Candle
and inject CandleSeries
module into the services
.
import * as React from "react";
import * as ReactDOM from "react-dom";
import { ChartComponent, SeriesCollectionDirective, SeriesDirective, Inject, Category, Tooltip, Zoom, Crosshair, CandleSeries } from '@syncfusion/ej2-react-charts';
import { chartData } from './datasource';
function App() {
const primaryxAxis = { title: 'Date', valueType: 'Category', majorGridLines: { width: 0 } };
const primaryyAxis = { title: 'Price in Dollar', minimum: 100, maximum: 200, interval: 20 };
const style = { textAlign: "center" };
const legendSettings = { visible: false };
return <ChartComponent id='charts' style={style} primaryXAxis={primaryxAxis} primaryYAxis={primaryyAxis} legendSettings={legendSettings} title='Shirpur Gold Refinery Share Price'>
<Inject services={[CandleSeries, Tooltip, Category, Crosshair, Zoom]}/>
<SeriesCollectionDirective>
<SeriesDirective dataSource={chartData} xName='x' yName='low' name='SHIRPUR-G' type='Candle' low='low' high='high' open='open' close='close'>
</SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>;
}
;
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));
import * as React from "react";
import * as ReactDOM from "react-dom";
import { AxisModel, ChartComponent, SeriesCollectionDirective, SeriesDirective, Inject,LegendSettingsModel,
Legend, Category, Tooltip, DataLabel, Zoom, Crosshair, CandleSeries, Selection}
from'@syncfusion/ej2-react-charts';
import { chartData } from './datasource';
function App() {
const primaryxAxis: AxisModel = { title: 'Date', valueType: 'Category', majorGridLines: { width: 0 } };
const primaryyAxis: AxisModel = { title: 'Price in Dollar', minimum: 100, maximum: 200, interval: 20 };
const style: any = { textAlign: "center" };
const legendSettings: LegendSettingsModel = { visible: false };
return <ChartComponent id='charts' style={style}
primaryXAxis={primaryxAxis}
primaryYAxis={primaryyAxis}
legendSettings={legendSettings}
title='Shirpur Gold Refinery Share Price'>
<Inject services={[CandleSeries, Tooltip, Category, Crosshair, Zoom]} />
<SeriesCollectionDirective>
<SeriesDirective dataSource={chartData} xName='x' yName='low' name='SHIRPUR-G' type='Candle' low='low'
high='high' open='open' close='close'>
</SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>
};
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));
Hollow Candles
Candle charts allow to visually compare the current price with previous price by coloring them.
Candles are filled/left as hollow based on the following criteria.
States | Description |
Filled | candle sticks are filled when the close value is lesser than the open value |
Unfilled | candle sticks are unfilled when the close value is greater than the open value |
The color of the candle will be defined by comparing with previous values. Bear color will be applied when the current closing value is greater than the previous closing value. Bull color will be applied when the current closing value is less than the previous closing value.
By default, bullFillColor is set as red and bearFillColor is set as green.
Solid Candles
enableSolidCandles
is used to enable/disable the solid candles. By default is set to be false. The fill color of the candle will be defined by its opening and closing values.
bearFillColor
will be applied when the opening value is less than the closing value.
bullFillColor
will be applied when the opening value is greater than closing value.
import * as React from "react";
import * as ReactDOM from "react-dom";
import { ChartComponent, SeriesCollectionDirective, SeriesDirective, Inject, Category, Tooltip, Zoom, Crosshair, CandleSeries } from '@syncfusion/ej2-react-charts';
import { chartData } from './datasource';
function App() {
const primaryxAxis = { title: 'Date', valueType: 'Category', majorGridLines: { width: 0 } };
const primaryyAxis = { title: 'Price in Dollar', minimum: 100, maximum: 200, interval: 20 };
const style = { textAlign: "center" };
const legendSettings = { visible: false };
return <ChartComponent id='charts' style={style} primaryXAxis={primaryxAxis} primaryYAxis={primaryyAxis} legendSettings={legendSettings} title='Shirpur Gold Refinery Share Price'>
<Inject services={[CandleSeries, Tooltip, Category, Crosshair, Zoom]}/>
<SeriesCollectionDirective>
<SeriesDirective dataSource={chartData} xName='x' yName='low' name='SHIRPUR-G' type='Candle' low='low' high='high' open='open' close='close' bearFillColor='#e56590' bullFillColor='#f8b883'>
</SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>;
}
;
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));
import * as React from "react";
import * as ReactDOM from "react-dom";
import { AxisModel, ChartComponent, SeriesCollectionDirective, SeriesDirective, Inject,LegendSettingsModel,
Legend, Category, Tooltip, DataLabel, Zoom, Crosshair, CandleSeries, Selection}
from'@syncfusion/ej2-react-charts';
import { chartData } from './datasource';
function App() {
const primaryxAxis: AxisModel = { title: 'Date', valueType: 'Category', majorGridLines: { width: 0 } };
const primaryyAxis: AxisModel = { title: 'Price in Dollar', minimum: 100, maximum: 200, interval: 20 };
const style: any = { textAlign: "center" };
const legendSettings: LegendSettingsModel = { visible: false };
return <ChartComponent id='charts' style={style}
primaryXAxis={primaryxAxis}
primaryYAxis={primaryyAxis}
legendSettings={legendSettings}
title='Shirpur Gold Refinery Share Price'>
<Inject services={[CandleSeries, Tooltip, Category, Crosshair, Zoom]} />
<SeriesCollectionDirective>
<SeriesDirective dataSource={chartData} xName='x' yName='low' name='SHIRPUR-G' type='Candle' low='low'
high='high' open='open' close='close' bearFillColor='#e56590' bullFillColor='#f8b883'>
</SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>
};
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));