Learn how to create Financial Charts with minimal configuration and customisations.
Default Configuration Copy Link
import React, { useState } from "react";
import { createRoot } from "react-dom/client";
import { AgFinancialCharts } from "ag-charts-react";
import {
AgFinancialChartOptions,
FinancialChartModule,
ModuleRegistry,
} from "ag-charts-enterprise";
import { getData } from "./data";
ModuleRegistry.registerModules([FinancialChartModule]);
const ChartExample = () => {
const [options, setOptions] = useState<AgFinancialChartOptions>({
data: getData(),
});
return <AgFinancialCharts options={options} />;
};
const root = createRoot(document.getElementById("root")!);
root.render(<ChartExample />);
Financial Charts come pre-configured with built-in features – just add your data to produce the chart shown above.
import React, { useState } from 'react';
import { createRoot } from 'react-dom/client';
import { AgFinancialCharts } from 'ag-charts-react';
import { AgFinancialChartOptions } from 'ag-charts-enterprise';
import { getData } from './data';
import 'ag-charts-enterprise';
const ChartExample = () => {
const [options, setOptions] = useState<AgFinancialChartOptions>({
data: getData(),
});
return <AgFinancialCharts options={options} />;
};
const root = createRoot(document.getElementById('root')!);
root.render(<ChartExample />);This snippet assumes the supplied data includes 'date', 'open', 'high', 'low', 'close' and 'volume' (optional) keys.
For custom data keys, map your data properties to the appropriate AgFinancialChartOptions keys:
dateKey: key for the date values.openKey: key for the open values.highKey: key for the high values.lowKey: key for the low values.closeKey: key for the close values.volumeKey: key for the volume values (optional).
Customisation Copy Link
Chart Features Copy Link
import React, { useState, Fragment } from "react";
import { createRoot } from "react-dom/client";
import { AgFinancialCharts } from "ag-charts-react";
import {
AgFinancialChartOptions,
FinancialChartModule,
ModuleRegistry,
} from "ag-charts-enterprise";
import { getData, getVolumeProfile } from "./data";
import clone from "clone";
ModuleRegistry.registerModules([FinancialChartModule]);
const ChartExample = () => {
const [options, setOptions] = useState<AgFinancialChartOptions>({
data: getData(),
navigator: false, // disabled by default!
toolbar: true,
rangeButtons: true,
volume: true,
statusBar: true,
zoom: true,
volumeProfile: {
enabled: false,
data: getVolumeProfile(),
upKey: "upVolume",
downKey: "downVolume",
},
});
const toggleFeature = (
type:
| "navigator"
| "toolbar"
| "rangeButtons"
| "volume"
| "statusBar"
| "zoom",
) => {
const nextOptions = clone(options);
nextOptions[type] = !nextOptions[type];
document
.getElementById(`toggle-${type}`)
?.setAttribute("aria-pressed", String(nextOptions[type]));
setOptions(nextOptions);
};
const toggleVolumeProfile = () => {
const nextOptions = clone(options);
nextOptions.volumeProfile!.enabled = !nextOptions.volumeProfile!.enabled;
document
.getElementById("toggle-volumeProfile")
?.setAttribute(
"aria-pressed",
String(nextOptions.volumeProfile!.enabled),
);
setOptions(nextOptions);
};
return (
<Fragment>
<div className="example-controls">
<div className="controls-row">
Toggle:
<button
id="toggle-navigator"
aria-pressed="false"
onClick={() => toggleFeature("navigator")}
>
Navigator
</button>
<button
id="toggle-toolbar"
aria-pressed="true"
onClick={() => toggleFeature("toolbar")}
>
Toolbar
</button>
<button
id="toggle-rangeButtons"
aria-pressed="true"
onClick={() => toggleFeature("rangeButtons")}
>
Range Buttons
</button>
<button
id="toggle-volume"
aria-pressed="true"
onClick={() => toggleFeature("volume")}
>
Volume
</button>
<button
id="toggle-statusBar"
aria-pressed="true"
onClick={() => toggleFeature("statusBar")}
>
Status Bar
</button>
<button
id="toggle-zoom"
aria-pressed="true"
onClick={() => toggleFeature("zoom")}
>
Zoom
</button>
<button
id="toggle-volumeProfile"
aria-pressed="false"
onClick={toggleVolumeProfile}
>
Volume Profile
</button>
</div>
</div>
<AgFinancialCharts options={options} />
</Fragment>
);
};
const root = createRoot(document.getElementById("root")!);
root.render(<ChartExample />);
Financial Chart features can be enabled or disabled via the following properties:
const options: AgFinancialChartOptions = {
// ...
toolbar: true,
rangeButtons: true,
volume: true,
statusBar: true,
zoom: true,
// disabled by default
navigator: false,
volumeProfile: { enabled: false /*other volume profile options*/ },
};In this configuration:
navigator: Enables the mini chart navigator for easy dataset navigation.toolbar: Shows the Toolbar.rangeButtons: Provides range buttons for navigating different time periods.volume: Displays volume data on the chart.statusBar: Shows a status bar at the top of the chart when hovering over the chart series.zoom: Enables zoom functionality for detailed analysis of the data.volumeProfile: Shows a Volume Profile of the volume traded at each price level.
Chart Types Copy Link
End users can use the Chart Type Selection Tool to choose a series type for visualising the data. However, this can also be done programmatically.
The default chart type is candlestick. To use a different chart type, set the chartType property.
import React, { useState, Fragment } from "react";
import { createRoot } from "react-dom/client";
import { AgFinancialCharts } from "ag-charts-react";
import {
AgFinancialChartOptions,
FinancialChartModule,
ModuleRegistry,
} from "ag-charts-enterprise";
import { getData } from "./data";
import clone from "clone";
ModuleRegistry.registerModules([FinancialChartModule]);
const ChartExample = () => {
const [options, setOptions] = useState<AgFinancialChartOptions>({
data: getData(),
chartType: "candlestick", // default!
});
const changeType = (event: Event) => {
const nextOptions = clone(options);
nextOptions.chartType = (event.target as HTMLInputElement)
.value as AgFinancialChartOptions["chartType"];
setOptions(nextOptions);
};
return (
<Fragment>
<div className="example-controls">
<div className="controls-row">
<div className="button-group" role="group" aria-label="Chart Type">
<input
type="radio"
id="type-candlestick"
name="chart-type"
defaultValue="candlestick"
defaultChecked
onChange={(event) => changeType(event)}
/>
<label htmlFor="type-candlestick">Candlestick (Default)</label>
<input
type="radio"
id="type-ohlc"
name="chart-type"
defaultValue="ohlc"
onChange={(event) => changeType(event)}
/>
<label htmlFor="type-ohlc">OHLC</label>
<input
type="radio"
id="type-hollow-candlestick"
name="chart-type"
defaultValue="hollow-candlestick"
onChange={(event) => changeType(event)}
/>
<label htmlFor="type-hollow-candlestick">Hollow Candlestick</label>
<input
type="radio"
id="type-line"
name="chart-type"
defaultValue="line"
onChange={(event) => changeType(event)}
/>
<label htmlFor="type-line">Line</label>
<input
type="radio"
id="type-step-line"
name="chart-type"
defaultValue="step-line"
onChange={(event) => changeType(event)}
/>
<label htmlFor="type-step-line">Step Line</label>
<input
type="radio"
id="type-hlc"
name="chart-type"
defaultValue="hlc"
onChange={(event) => changeType(event)}
/>
<label htmlFor="type-hlc">HLC</label>
<input
type="radio"
id="type-high-low"
name="chart-type"
defaultValue="high-low"
onChange={(event) => changeType(event)}
/>
<label htmlFor="type-high-low">High Low</label>
</div>
</div>
</div>
<AgFinancialCharts options={options} />
</Fragment>
);
};
const root = createRoot(document.getElementById("root")!);
root.render(<ChartExample />);
const options: AgFinancialChartOptions = {
// ...
chartType: 'line', // Set to line
};The chart type state can be saved, restored and programmatically initialised and modified, using the Chart State API.
The following chart types are supported:
candlestick,hollow-candlestick,ohlc,line,step-line,hlc,high-low.
Chart Styling Copy Link
import React, { useState } from "react";
import { createRoot } from "react-dom/client";
import { AgFinancialCharts } from "ag-charts-react";
import {
AgFinancialChartOptions,
FinancialChartModule,
ModuleRegistry,
} from "ag-charts-enterprise";
import { getData } from "./data";
ModuleRegistry.registerModules([FinancialChartModule]);
const ChartExample = () => {
const [options, setOptions] = useState<AgFinancialChartOptions>({
theme: {
palette: {
up: { fill: "#F3A93C", stroke: "#A8492D" },
down: { fill: "#1A00F4", stroke: "#75FBFD" },
},
},
data: getData(),
});
return <AgFinancialCharts options={options} />;
};
const root = createRoot(document.getElementById("root")!);
root.render(<ChartExample />);
Use the theme property in AgFinancialChartOptions to customise chart styles.
const options: AgFinancialChartOptions = {
// ...
theme: {
palette: {
up: { fill: '#F3A93C', stroke: '#A8492D' },
down: { fill: '#1A00F4', stroke: '#75FBFD' },
},
},
};In this configuration:
palette: Specifies custom colours.up: Colours for "rising values"down: Colours for "falling values"
For additional customisation, use Theme Override Options in the theme option.
Financial Charts use the ag-financial and ag-financial-dark themes.
API Reference Copy Link
Properties available on the AgFinancialChartOptions interface.
- theme
AgChartTheme | AgChartThemeName - A predefined theme name or an object containing theme overrides. See: [Themes Reference](/themes-api/)
- listeners
AgAxesChartListeners - A map of event names to event listeners.
- data
DatumDefault[] - The data to render the chart from. If this is not specified, it must be set on individual series instead.
- dataIdKey
DatumKey - The key of the property on each datum that contains its unique identifier. When specified, transactions will match items by this field instead of by object reference. The values of this field must be unique across the dataset.
- container
HTMLElement | null - The element to place the rendered chart into.
- initialState
AgInitialStateOptions - The initial state of the chart. This must be a serialisable value.
- width
PixelSize - The width of the chart in pixels.
- height
PixelSize - The height of the chart in pixels.
- minHeight
PixelSizedefault: 300 - Sets the minimum height of the chart. Ignored if `height` is specified.
- minWidth
PixelSizedefault: 300 - Sets the minimum width of the chart. Ignored if `width` is specified.
- title
AgChartCaptionOptions - Configuration for the title shown at the top of the chart.
- dataSource
AgDataSourceOptions - Configuration for asynchronously loaded data.
- formatter
FormatterConfiguration - Global formatter configuration.
- enableRtl
boolean - Set to `true` to render the chart in right-to-left mode. If not specified, the chart will detect the `dir` attribute on the container or its ancestors.
- chartType
AgPriceVolumeChartTypedefault: 'candlestick' - Series type used for the OHLC data.
- dateKey
stringdefault: 'date' - The key used to retrieve x-values from the data.
- openKey
stringdefault: 'open' - The key used to retrieve 'open' values from the data.
- highKey
stringdefault: 'high' - The key used to retrieve 'high' values from the data.
- lowKey
stringdefault: 'low' - The key used to retrieve 'low' values from the data.
- closeKey
stringdefault: 'close' - The key used to retrieve 'close' values from the data.
- volumeKey
stringdefault: 'volume' - The key used to retrieve 'volume' values from the data.
- volume
booleandefault: true - Whether to show the volume series at the bottom of the chart.
- volumeProfile
AgVolumeProfileOptions - Configuration for a Volume Profile, showing the traded volume at each price level as horizontal bars against the price axis.
- tickSize
number - The height of each Volume Profile price level, in price units. If not set, the smallest gap between the prices in `volumeProfile.data` is used.
- rangeButtons
booleandefault: true - Whether to show the range buttons.
- statusBar
booleandefault: true - Whether to show the status bar.
- toolbar
booleandefault: true - Whether the toolbar is enabled.
- zoom
booleandefault: true - Whether Zoom is enabled.
- sync
booleandefault: false - Whether to enable chart synchronization.
Properties available on the AgFinancialChartOptions interface.
- theme
AgChartTheme | AgChartThemeName - A predefined theme name or an object containing theme overrides. See: [Themes Reference](/themes-api/)
- listeners
AgAxesChartListeners - A map of event names to event listeners.
- data
DatumDefault[] - The data to render the chart from. If this is not specified, it must be set on individual series instead.
- dataIdKey
DatumKey - The key of the property on each datum that contains its unique identifier. When specified, transactions will match items by this field instead of by object reference. The values of this field must be unique across the dataset.
- container
HTMLElement | null - The element to place the rendered chart into.
- initialState
AgInitialStateOptions - The initial state of the chart. This must be a serialisable value.
- width
PixelSize - The width of the chart in pixels.
- height
PixelSize - The height of the chart in pixels.
- minHeight
PixelSizedefault: 300 - Sets the minimum height of the chart. Ignored if `height` is specified.
- minWidth
PixelSizedefault: 300 - Sets the minimum width of the chart. Ignored if `width` is specified.
- title
AgChartCaptionOptions - Configuration for the title shown at the top of the chart.
- dataSource
AgDataSourceOptions - Configuration for asynchronously loaded data.
- formatter
FormatterConfiguration - Global formatter configuration.
- enableRtl
boolean - Set to `true` to render the chart in right-to-left mode. If not specified, the chart will detect the `dir` attribute on the container or its ancestors.
- chartType
AgPriceVolumeChartTypedefault: 'candlestick' - Series type used for the OHLC data.
- dateKey
stringdefault: 'date' - The key used to retrieve x-values from the data.
- openKey
stringdefault: 'open' - The key used to retrieve 'open' values from the data.
- highKey
stringdefault: 'high' - The key used to retrieve 'high' values from the data.
- lowKey
stringdefault: 'low' - The key used to retrieve 'low' values from the data.
- closeKey
stringdefault: 'close' - The key used to retrieve 'close' values from the data.
- volumeKey
stringdefault: 'volume' - The key used to retrieve 'volume' values from the data.
- volume
booleandefault: true - Whether to show the volume series at the bottom of the chart.
- volumeProfile
AgVolumeProfileOptions - Configuration for a Volume Profile, showing the traded volume at each price level as horizontal bars against the price axis.
- tickSize
number - The height of each Volume Profile price level, in price units. If not set, the smallest gap between the prices in `volumeProfile.data` is used.
- rangeButtons
booleandefault: true - Whether to show the range buttons.
- statusBar
booleandefault: true - Whether to show the status bar.
- toolbar
booleandefault: true - Whether the toolbar is enabled.
- zoom
booleandefault: true - Whether Zoom is enabled.
- sync
booleandefault: false - Whether to enable chart synchronization.