Candle in React Chart component
4 Apr 202313 minutes to read
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';
function App() {
const chartData = [
{ x: 'Jan', open: 120, high: 160, low: 100, close: 140 },
{ x: 'Feb', open: 150, high: 190, low: 130, close: 170 },
{ x: 'Mar', open: 130, high: 170, low: 110, close: 150 },
{ x: 'Apr', open: 160, high: 180, low: 120, close: 140 },
{ x: 'May', open: 150, high: 170, low: 110, close: 130 }
];
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';
function App() {
const chartData: any[] = [
{ x: 'Jan', open: 120, high: 160, low: 100, close: 140 },
{ x: 'Feb', open: 150, high: 190, low: 130, close: 170 },
{ x: 'Mar', open: 130, high: 170, low: 110, close: 150 },
{ x: 'Apr', open: 160, high: 180, low: 120, close: 140 },
{ x: 'May', open: 150, high: 170, low: 110, close: 130 }
];
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';
function App() {
const chartData = [
{ x: 'Jan', open: 120, high: 160, low: 100, close: 140 },
{ x: 'Feb', open: 150, high: 190, low: 130, close: 170 },
{ x: 'Mar', open: 130, high: 170, low: 110, close: 150 },
{ x: 'Apr', open: 160, high: 180, low: 120, close: 140 },
{ x: 'May', open: 150, high: 170, low: 110, close: 130 }
];
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';
function App() {
const chartData: any[] = [
{ x: 'Jan', open: 120, high: 160, low: 100, close: 140 },
{ x: 'Feb', open: 150, high: 190, low: 130, close: 170 },
{ x: 'Mar', open: 130, high: 170, low: 110, close: 150 },
{ x: 'Apr', open: 160, high: 180, low: 120, close: 140 },
{ x: 'May', open: 150, high: 170, low: 110, close: 130 }
];
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"));