Loading...
Loading...
Implements the Syncfusion React Stock Chart component for visualizing financial and market data. Use this when users need stock price visualization, OHLC charts, candlestick charts, or trading chart interfaces. Supports multiple series types, period selectors, range navigators, technical indicators (e.g., SMA, MACD, Bollinger Bands), and interactive analysis tools for financial data in React applications.
npx skill4agent add syncfusion/react-ui-components-skills syncfusion-react-stock-chart@syncfusion/ej2-react-chartsStockChartComponentindicatorTypestockEventsstockEventRenderselectionModeisMultiSelectselectedDataIndexeszoomSettingsonZoomingexportTypeExportPrintenablePersistenceenableRtlenableenable: truecrosshairTooltipcrosshairTooltipaxesimport { StockChartComponent, StockChartSeriesCollectionDirective,
StockChartSeriesDirective, Inject, DateTime, Tooltip,
RangeTooltip, Crosshair, LineSeries, SplineSeries,
CandleSeries, HiloOpenCloseSeries, HiloSeries,
RangeAreaSeries, Trendlines } from '@syncfusion/ej2-react-charts';
import * as React from 'react';
function App() {
const data = [
{ x: new Date('2012-04-02'), open: 85.97, high: 90.58, low: 85.97, close: 90.58, volume: 660187068 },
{ x: new Date('2012-04-09'), open: 89.02, high: 92.50, low: 88.50, close: 92.90, volume: 490033264 },
{ x: new Date('2012-04-16'), open: 92.52, high: 93.00, low: 88.50, close: 92.52, volume: 450167016 },
// ... more data
];
return (
<StockChartComponent
id='stockchart'
title='AAPL Stock Price'
primaryXAxis={{ valueType: 'DateTime' }}
>
<Inject services={[DateTime, Tooltip, RangeTooltip, Crosshair, LineSeries,
SplineSeries, CandleSeries, HiloOpenCloseSeries, HiloSeries,
RangeAreaSeries, Trendlines]} />
<StockChartSeriesCollectionDirective>
<StockChartSeriesDirective
dataSource={data}
type='Candle'
xName='x'
high='high'
low='low'
open='open'
close='close'
volume='volume'
/>
</StockChartSeriesCollectionDirective>
</StockChartComponent>
);
}
export default App;import { StockChartComponent, StockChartSeriesCollectionDirective,
StockChartSeriesDirective, Inject, DateTime, Tooltip,
RangeTooltip, Crosshair, CandleSeries } from '@syncfusion/ej2-react-charts';
function App() {
const data = [ /* stock data */ ];
const periods = [
{ intervalType: 'Days', interval: 1, text: '1D' },
{ intervalType: 'Days', interval: 5, text: '5D' },
{ intervalType: 'Months', interval: 1, text: '1M' },
{ intervalType: 'Months', interval: 3, text: '3M' },
{ intervalType: 'Months', interval: 6, text: '6M' },
{ intervalType: 'Years', interval: 1, text: '1Y' },
{ text: 'All' }
];
return (
<StockChartComponent
id='stockchart'
title='Stock Analysis'
primaryXAxis={{ valueType: 'DateTime' }}
periods={periods}
enablePeriodSelector={true}
>
<Inject services={[DateTime, Tooltip, RangeTooltip, Crosshair, CandleSeries]} />
<StockChartSeriesCollectionDirective>
<StockChartSeriesDirective
dataSource={data}
type='Candle'
xName='x'
high='high'
low='low'
open='open'
close='close'
/>
</StockChartSeriesCollectionDirective>
</StockChartComponent>
);
}<link><head>index.html<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<!-- Syncfusion Tailwind CSS for Stock Chart styling -->
<link href="https://cdn.syncfusion.com/ej2/33.1.44/tailwind3.css" rel="stylesheet" />
<!-- Bootstrap CSS for additional styling support -->
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<title>Stock Chart App</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>tailwind3.csshttps://cdn.syncfusion.com/ej2/33.1.44/tailwind3.csshttps://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css@syncfusion/ej2-react-chartshttps://cdn.syncfusion.com/ej2/33.1.44/material.csshttps://cdn.syncfusion.com/ej2/33.1.44/bootstrap.csshttps://cdn.syncfusion.com/ej2/33.1.44/fabric.csshttps://cdn.syncfusion.com/ej2/33.1.44/tailwind3.csshttps://cdn.syncfusion.com/ej2/33.1.44/highcontrast.cssprimaryXAxis={{
valueType: 'DateTime',
majorGridLines: { width: 0 },
majorTickLines: { color: 'transparent' }
}}DateTimeprimaryXAxis={{
valueType: 'DateTimeCategory',
majorGridLines: { width: 0 }
}}DateTimeCategoryDateTimeCategoryprimaryYAxis={{
valueType: 'Logarithmic',
labelFormat: '${value}'
}}LogarithmicprimaryYAxis={{
valueType: 'Double',
labelFormat: '${value}',
minimum: 0,
maximum: 500,
interval: 50
}}<StockChartComponent
primaryXAxis={{ valueType: 'DateTime' }}
primaryYAxis={{ title: 'Price', labelFormat: '${value}' }}
>
{/* Additional axes using StockChartAxesDirective */}
<StockChartAxesDirective>
<StockChartAxisDirective
name='volumeAxis'
opposedPosition={true}
title='Volume'
labelFormat='{value}M'
/>
</StockChartAxesDirective>
{/* Series bind to respective axes */}
<StockChartSeriesCollectionDirective>
<StockChartSeriesDirective type='Candle' yAxisName='primaryYAxis' />
<StockChartSeriesDirective type='Column' yAxisName='volumeAxis' />
</StockChartSeriesCollectionDirective>
</StockChartComponent>import { StockChartComponent, StockChartSeriesCollectionDirective,
StockChartSeriesDirective, Inject, DateTime, Tooltip,
RangeTooltip, Crosshair, CandleSeries, StockLegend,
Export, Print } from '@syncfusion/ej2-react-charts';
function FinancialDashboard() {
const handlePointClick = (args) => {
console.log(`Point clicked: ${args.x}, Value: ${args.y}`);
};
const handleMouseMove = (args) => {
console.log('Mouse moved over chart');
};
const handleRangeChange = (args) => {
console.log(`Range changed: ${args.start} to ${args.end}`);
};
return (
<StockChartComponent
id='stockchart'
title='Comprehensive Stock Analysis'
primaryXAxis={{ valueType: 'DateTime' }}
tooltip={{ enable: true, shared: true }}
crosshair={{ enable: true }}
legendSettings={{ visible: true }}
enablePeriodSelector={true}
enableSelector={true}
pointClick={handlePointClick}
stockChartMouseMove={handleMouseMove}
rangeChange={handleRangeChange}
>
<Inject services={[DateTime, Tooltip, RangeTooltip, Crosshair,
CandleSeries, StockLegend, Export, Print]} />
<StockChartSeriesCollectionDirective>
<StockChartSeriesDirective
dataSource={stockData}
type='Candle'
name='Apple Inc'
/>
</StockChartSeriesCollectionDirective>
</StockChartComponent>
);
}function StyledCandleChart() {
const stockData = [ /* stock data with open, high, low, close */ ];
return (
<StockChartComponent
id='stockchart'
primaryXAxis={{ valueType: 'DateTime' }}
primaryYAxis={{ labelFormat: '${value}' }}
>
<Inject services={[DateTime, CandleSeries, Tooltip, RangeTooltip]} />
<StockChartSeriesCollectionDirective>
<StockChartSeriesDirective
dataSource={stockData}
type='Candle'
xName='x'
open='open'
high='high'
low='low'
close='close'
bearFillColor='#ef5350' // Red for downtrend
bullFillColor='#26a69a' // Green for uptrend
animation={{ enable: true, duration: 500 }}
/>
</StockChartSeriesCollectionDirective>
</StockChartComponent>
);
}function TechnicalAnalysisChart() {
const indicators = [
{
type: 'Sma',
field: 'Close',
period: 14,
fill: 'blue'
},
{
type: 'BollingerBands',
field: 'Close',
period: 20,
standardDeviation: 2,
upperLine: { color: '#ff0000', width: 1 },
lowerLine: { color: '#ff0000', width: 1 }
}
];
return (
<StockChartComponent
id='stockchart'
primaryXAxis={{ valueType: 'DateTime' }}
indicators={indicators}
>
<Inject services={[DateTime, CandleSeries, Tooltip,
LineSeries, RangeTooltip, SmaIndicator, BollingerBands]} />
<StockChartSeriesCollectionDirective>
<StockChartSeriesDirective
dataSource={stockData}
type='Candle'
/>
</StockChartSeriesCollectionDirective>
<StockChartIndicatorsDirective>
{/* Indicators can also be added here via directives */}
</StockChartIndicatorsDirective>
</StockChartComponent>
);
}function CrosshairChart() {
return (
<StockChartComponent
id='stockchart'
primaryXAxis={{
valueType: 'DateTime',
majorGridLines: { width: 0 },
majorTickLines: { color: 'transparent' },
crosshairTooltip: { enable: true } // X-axis tooltip
}}
primaryYAxis={{
labelFormat: 'n0',
majorTickLines: { width: 0 },
crosshairTooltip: { enable: true } // Y-axis tooltip
}}
crosshair={{
enable: true,
lineType: 'Both',
line: { width: 1, color: '#0080ff' }
}}
tooltip={{ enable: true }}
>
<Inject services={[DateTime, CandleSeries, Crosshair, Tooltip, RangeTooltip]} />
<StockChartSeriesCollectionDirective>
<StockChartSeriesDirective
dataSource={stockData}
type='Candle'
/>
</StockChartSeriesCollectionDirective>
</StockChartComponent>
);
}function StockEventsChart() {
const stockEvents = [
{
date: new Date('2012-04-01'),
text: 'Q1 Earnings',
description: 'Quarterly earnings release',
type: 'Flag',
background: '#6c757d'
},
{
date: new Date('2012-07-01'),
text: 'Dividend',
description: 'Dividend payout',
type: 'Circle',
background: '#28a745'
}
];
return (
<StockChartComponent
id='stockchart'
primaryXAxis={{ valueType: 'DateTime' }}
stockEvents={stockEvents}
>
<Inject services={[DateTime, SplineSeries, Tooltip]} />
<StockChartSeriesCollectionDirective>
<StockChartSeriesDirective
dataSource={stockData}
type='Spline'
/>
</StockChartSeriesCollectionDirective>
</StockChartComponent>
);
}function ExportableChart() {
const chartRef = useRef<StockChartComponent>(null);
const handleExport = (type: string) => {
if (chartRef.current) {
chartRef.current.export(type, 'StockChart');
}
};
const handlePrint = () => {
if (chartRef.current) {
chartRef.current.print();
}
};
return (
<div>
<div>
<button onClick={() => handleExport('PNG')}>Export PNG</button>
<button onClick={() => handleExport('JPEG')}>Export JPEG</button>
<button onClick={() => handleExport('SVG')}>Export SVG</button>
<button onClick={() => handleExport('PDF')}>Export PDF</button>
<button onClick={handlePrint}>Print Chart</button>
</div>
<StockChartComponent
ref={chartRef}
id='stockchart'
primaryXAxis={{ valueType: 'DateTime' }}
exportType={['PNG', 'JPEG', 'SVG', 'PDF']}
>
<Inject services={[DateTime, CandleSeries, Export]} />
<StockChartSeriesCollectionDirective>
<StockChartSeriesDirective
dataSource={stockData}
type='Candle'
/>
</StockChartSeriesCollectionDirective>
</StockChartComponent>
</div>
);
}| Prop | Type | Description |
|---|---|---|
| Object | X-axis configuration (typically DateTime) |
| Object | Y-axis configuration |
| Array | Additional Y-axes for multi-axis scaling |
| string | Chart title |
| Object | Title font styling |
| Array | Period selector buttons configuration |
| boolean | Show/hide period selector (default: true) |
| boolean | Show/hide range selector (default: true) |
| boolean | Enable custom date range selection |
| Object | Tooltip configuration |
| Object | Crosshair configuration |
| Object | Legend configuration |
| Array | Stock event markers |
| Array | Technical indicators |
| string | Chart height |
| string | Chart width |
| Object | Chart margin configuration |
| Object | Chart area styling |
| string | Chart background color |
| Object | Chart border configuration |
| string | Chart theme |
| Object | Zoom and pan configuration |
| Array | Row definitions for multi-row layouts |
| Array | Programmatically select specific points |
| string | Selection mode (None, Point, Series, Cluster, DragXY, DragX, DragY) |
| boolean | Allow multiple data point selection |
| Array | Export formats (PNG, JPEG, SVG, PDF) |
| boolean | Persist chart state between page reloads |
| boolean | Enable right-to-left rendering |
| string | Override global culture/localization |
| string/Function | Template shown when no data available |
| boolean | Render chart in transposed manner |
| Array | Available series types |
| Array | Available technical indicator types |
| Array | Available trendline types |
| string | Fill color for downtrend (bear) candles |
| string | Fill color for uptrend (bull) candles |
| Object | Animation settings for series rendering |
| Function | Event fired when a data point is clicked |
| Function | Event fired when mouse moves over chart |
| Function | Event fired when chart area is clicked |
| Function | Event fired on mouse down |
| Function | Event fired on mouse up |
| Function | Event fired when cursor leaves chart |
| Function | Event for customizing tooltip before display |
| Function | Event for customizing axis labels before rendering |
| Function | Event fired when series is rendered |
| Function | Event fired when legend item is clicked |
| Function | Event fired when legend items are rendered |
| Function | Event fired before crosshair tooltip is rendered |
| Function | Triggered when range selector renders |
| Function | Event fired during zoom interactions |
| Function | Lifecycle event fired before chart is loaded |
| Function | Lifecycle event fired after chart is loaded |
| Function | Event fired before export operation |
| Function | Customize stock event marker rendering |
| Array | Row definitions for multi-row layouts |
| boolean | Render chart in transposed manner |
| Array | Trend line configurations (StockChartTrendlinesDirective) |
| Prop | Type | Description |
|---|---|---|
| Array | Stock data array |
| string | Series type (Candle, Line, Spline, Hilo, HiloOpenClose) |
| string | Data field for x-axis (date) |
| string | Data field for high values |
| string | Data field for low values |
| string | Data field for open values |
| string | Data field for close values |
| string | Data field for volume values |
| string | Series name for legend |
| string | Data field for y-axis values |
| string | Name of Y-axis to bind this series to (for multi-axis) |
| string | Fill color for downtrend candles/bars |
| string | Fill color for uptrend candles/bars |
| string | Series color or gradient fill (e.g., 'url(#gradient1)') |
| number | Line width for series |
| number | Opacity of series (0-1) |
| Object | Border configuration for series (width, color, dashArray) |
| Object | Data point marker configuration (visible, size, shape, fill, border) |
| Object | Animation settings (enable, duration, delay) |
| string | Legend icon shape (Circle, Rectangle, Triangle, Diamond, etc.) |
| Object | Series-specific tooltip configuration |
| Array | Trend lines for this series |
| number | Corner radius for rectangular shapes |
import { Inject, DateTime, DateTimeCategory, Logarithmic,
Tooltip, RangeTooltip, Crosshair,
LineSeries, SplineSeries, CandleSeries, HiloOpenCloseSeries,
HiloSeries, RangeAreaSeries, StockLegend, Trendlines, Export } from '@syncfusion/ej2-react-charts';
import { EmaIndicator, RsiIndicator, BollingerBands, TmaIndicator,
MomentumIndicator, SmaIndicator, AtrIndicator,
AccumulationDistributionIndicator, MacdIndicator,
StochasticIndicator } from '@syncfusion/ej2-react-charts';
<StockChartComponent>
<Inject services={[DateTime, Tooltip, RangeTooltip, Crosshair,
CandleSeries, StockLegend, Trendlines, Export,
EmaIndicator, SmaIndicator, BollingerBands]} />
</StockChartComponent>// Point click event
const handlePointClick = (args) => {
console.log('Point clicked:', args.pointIndex, args.seriesIndex);
console.log('X:', args.x, 'Y:', args.y);
};
// Point move event (hover)
const handlePointMove = (args) => {
console.log('Hovering over point:', args.x);
};
<StockChartComponent
pointClick={handlePointClick}
pointMove={handlePointMove}
>
{/* ... */}
</StockChartComponent>// Various mouse tracking events
const handleMouseMove = (args) => {
console.log('Mouse position:', args.x, args.y);
};
const handleMouseLeave = (args) => {
console.log('Mouse left chart area');
};
const handleMouseClick = (args) => {
console.log('Chart clicked');
};
<StockChartComponent
stockChartMouseMove={handleMouseMove}
stockChartMouseLeave={handleMouseLeave}
stockChartMouseClick={handleMouseClick}
stockChartMouseDown={(args) => console.log('Mouse down')}
stockChartMouseUp={(args) => console.log('Mouse up')}
>
{/* ... */}
</StockChartComponent>// Range change event (period selector or range selector)
const handleRangeChange = (args) => {
console.log('Range changed:', args.start, 'to', args.end);
// Refresh data or update analysis
};
<StockChartComponent
rangeChange={handleRangeChange}
>
{/* ... */}
</StockChartComponent>// Legend click event
const handleLegendClick = (args) => {
console.log('Legend item clicked:', args.legendText);
};
// Legend render event (for customization)
const handleLegendRender = (args) => {
if (args.legendText === 'AAPL') {
args.fill = '#ff0000'; // Customize legend color
}
};
<StockChartComponent
legendClick={handleLegendClick}
legendRender={handleLegendRender}
>
{/* ... */}
</StockChartComponent>// Customize tooltip before rendering
const handleTooltipRender = (args) => {
args.text = `<b>Stock Price: ${args.text}</b>`;
};
<StockChartComponent
tooltip={{ enable: true }}
tooltipRender={handleTooltipRender}
>
{/* ... */}
</StockChartComponent>// Customize stock event markers
const handleStockEventRender = (args) => {
// Customize event styling, position, etc.
if (args.text === 'Earnings') {
args.background = '#ff0000'; // Custom color for earnings
}
};
<StockChartComponent
stockEvents={stockEvents}
stockEventRender={handleStockEventRender}
>
{/* ... */}
</StockChartComponent>// Load event (before rendering)
const handleLoad = (args) => {
console.log('Chart loading');
};
// Loaded event (after rendering)
const handleLoaded = (args) => {
console.log('Chart loaded');
};
<StockChartComponent
load={handleLoad}
loaded={handleLoaded}
>
{/* ... */}
</StockChartComponent>StockChartreferences/*dataSourcex, open, high, low, close, volumeseriesStockChartSeriesCollectionDirectiveprimaryXAxisvalueType: 'DateTime''DateTimeCategory''Numeric'crosshairTooltipmajorGridLinesmajorTickLinesprimaryYAxisvalueType: 'Double''Logarithmic'labelFormatrangePaddingminorGridLinescrosshairTooltipaxesStockChartAxesDirectiveStockChartAxisDirectiveperiodsintervalTypeintervaltextenablePeriodSelectorenableSelectorenableCustomRangeindicatorsstockEventstooltipenableformatsharedcrosshairenablelineTypelegendSettingsselectedDataIndexesselectionModeisMultiSelectthemebackgroundborderchartAreamargintitletitleStylewidthheightexportType[]enablePersistenceseriesStockChartSeriesCollectionDirectiveindicatorsStockChartIndicatorsDirectivetrendlinesStockChartTrendlinesDirectiveenableRtlzoomSettingsexport(type: string, fileName: string)print()destroy()getModuleName()renderPeriodSelector()rangeChanged(start: Date | number, end: Date | number)loadloadedaxisLabelRenderseriesRenderbeforeExportpointClickpointMovelegendClicklegendRendertooltipRenderrangeChangeonRangeChangeselectorRenderstockEventRenderonZoomingreferences/api.mdreferences/configuration.mdreferences/interactive-features.mdtooltipRenderpointClickaxisLabelRenderreferences/technical-analysis.mdindicatorsstockEvents<StockChartComponent
id="stockchart"
dataSource={data}
primaryXAxis={{ valueType: 'DateTime' }}
enablePeriodSelector={true}
indicators={[{ type: 'Sma', period: 14 }]}
stockEvents={[{ date: new Date(2023,0,1), text: 'Earnings' }]}
tooltip={{ enable: true }}
crosshair={{ enable: true }}
load={(args) => console.log('loading', args)}
loaded={(args) => console.log('loaded', args)}
axisLabelRender={(args) => {/* modify labels */}}
pointClick={(args) => {/* handle point click */}}
>
<Inject services={[DateTime, CandleSeries, Tooltip, Crosshair]} />
<StockChartSeriesCollectionDirective>
<StockChartSeriesDirective type="Candle" xName="x" open="open" high="high" low="low" close="close" />
</StockChartSeriesCollectionDirective>
</StockChartComponent>