⚛️ GoCharting React Component
The <GoCharting /> component is the declarative React API for the GoCharting SDK — an alternative to the imperative createChart() function. Render a full professional chart by mounting a component; React handles the mount/unmount lifecycle for you.
It mirrors createChart()’s configuration surface: every config option becomes a prop, and the appCallback contract is identical.
🚀 Quick Start
import { GoCharting } from "@gocharting/chart-sdk";
function App() {
return (
<GoCharting
symbol="NASDAQ:AAPL"
interval="1D"
datafeed={myDatafeed}
licenseKey="demo-550e8400-e29b-41d4-a716-446655440000"
theme="light"
height="600px"
onReady={(chart) => chart.addIndicator({ type: "EMA", id: "ema-20" })}
appCallback={(event) => console.log(event.eventType, event.message)}
/>
);
}Without JSX (UMD build)
const { React, ReactDOM, GoCharting } = window.GoChartingSDK;
ReactDOM.render(
React.createElement(GoCharting, {
symbol: "NASDAQ:AAPL",
interval: "1D",
datafeed: myDatafeed,
licenseKey: "demo-550e8400-e29b-41d4-a716-446655440000",
}),
document.getElementById("chart")
);📋 Props
Props mirror the createChart() configuration object — see the Configuration API for detailed descriptions of each option.
Core Props
| Prop | Type | Default | Description |
|---|---|---|---|
symbol | string | — | Initial symbol to display |
interval | string | — | Initial time interval |
datafeed | object | — | Datafeed object (see Datafeed API) |
licenseKey | string | — | Your SDK license key |
Display Props
| Prop | Type | Default | Description |
|---|---|---|---|
theme | string | "light" | Chart theme (‘light’ or ‘dark’) |
locale | string | "en-US" | Locale for translations |
autosize | boolean | true | Enable AutoFit responsive sizing |
width | string | number | "100%" | Chart width |
height | string | number | "100%" | Chart height |
Callback Props
| Prop | Type | Description |
|---|---|---|
appCallback | function | Receives a single { eventType, message, onClose } event object — same contract as createChart() (see Events API) |
onReady | function | Called with the imperative chart instance when the chart is mounted |
onError | function | Called on chart errors |
Feature & Override Props
| Prop | Type | Default | Description |
|---|---|---|---|
enableTrading | boolean | false | Enable trading features |
trading | object | — | Trading configuration override |
exclude | object | — | UI elements to exclude |
defaultInitialChartConfig | object | — | Chart configuration overrides |
themeColor | string | — | Theme color override |
contextMenu | object | — | Context menu options override |
popups | object | — | Popup preferences override |
favourite | object | — | User favorites override |
disableSearch | boolean | false | Hide search bar in top bar |
disableCompare | boolean | false | Hide compare button in top bar |
autoSave | boolean | true | Auto-save chart state to sessionStorage |
showCrosshairPlusIcon | boolean | true | Show the crosshair plus icon |
isNativeApp | boolean | false | Native/Flutter mode: hides TopBar, drawing side menu, and portals |
touchMode | boolean | false | Force touch/mobile mode regardless of user agent |
debugLog | boolean | false | Enable debug logging to console |
Unlike createChart(), the component does not expose skipLicenseValidation — license validation is always performed, so a valid licenseKey is required (use the demo key for evaluation).
🎛️ Imperative Access via Ref
Forward a ref to access the imperative chart instance — the same methods as the object returned by createChart() (setSymbol, setInterval, addIndicator, setTimezone, applyTemplate, setBrokerAccounts, …). See the Chart API for the full method reference.
import React, { useRef } from "react";
import { GoCharting } from "@gocharting/chart-sdk";
function TradingView() {
const chartRef = useRef(null);
return (
<div style={{ height: "600px" }}>
<button onClick={() => chartRef.current?.setSymbol("NASDAQ:MSFT")}>
Switch to MSFT
</button>
<button onClick={() => chartRef.current?.setInterval("1h")}>
1 Hour
</button>
<GoCharting
ref={chartRef}
symbol="NASDAQ:AAPL"
interval="1D"
datafeed={myDatafeed}
licenseKey="demo-550e8400-e29b-41d4-a716-446655440000"
/>
</div>
);
}Alternatively, capture the instance from onReady:
<GoCharting
symbol="NASDAQ:AAPL"
interval="1D"
datafeed={myDatafeed}
licenseKey="demo-550e8400-e29b-41d4-a716-446655440000"
onReady={(chart) => {
chart.addIndicator({ type: "RSI", id: "rsi-14" });
}}
/>📈 Trading Example
<GoCharting
symbol="BYBIT:FUTURE:BTCUSDT"
interval="1m"
datafeed={myDatafeed}
licenseKey="demo-550e8400-e29b-41d4-a716-446655440000"
theme="dark"
trading={{
enableTrading: true,
showOpenOrders: true,
showPositions: true,
}}
appCallback={(event) => {
switch (event.eventType) {
case "PLACE_ORDER":
submitToBroker(event.message.order);
if (event.onClose) event.onClose();
break;
case "CANCEL_ORDER":
cancelAtBroker(event.message.order);
break;
}
}}
onReady={(chart) => {
chart.setBrokerAccounts(myBrokerData);
}}
/>🆚 <GoCharting /> vs createChart()
| Aspect | <GoCharting /> | createChart() |
|---|---|---|
| Style | Declarative (JSX) | Imperative (function call) |
| Lifecycle | Managed by React (unmount cleans up) | You must call chart.destroy() |
| Imperative methods | Via ref or onReady instance | Via the returned ChartInstance |
| Container | Renders where mounted | Requires an HTMLElement or selector |
| Config surface | Same options as props | Same options in the config object |
| Best for | React applications | Vanilla JS, non-React frameworks |
🔗 Related Documentation
- Chart API - Imperative
createChart()API and instance methods - Configuration API - All configuration options
- Events API -
appCallbackevents and payloads - Datafeed API - Implement your data source
For a complete React integration walkthrough, see the React example.