βοΈ Configuration API
The Configuration API provides comprehensive control over chart behavior, appearance, and features through the ChartConfig object passed to createChart().
π ChartConfig Interface
The ChartConfig object is passed to createChart() and contains all configuration options for the chart.
import { createChart, ChartConfig } from "@gocharting/chart-sdk";
const config: ChartConfig = {
// Required properties
datafeed: myDatafeed,
symbol: "AAPL",
interval: "1D",
licenseKey: "YOUR_LICENSE_KEY",
// Display options
theme: "dark",
themeColor: "#1a1a1a",
autosize: true,
width: "100%",
height: "100%",
locale: "en-US",
// Feature flags
debugLog: false,
disableSearch: false,
disableCompare: false,
hideDrawingToolBar: false,
alwaysDrawMode: false,
autoSave: true,
// Configuration overrides
defaultInitialChartConfig: {
settings: {
showCrosshairPlusIcon: false,
zone: "America/New_York",
},
},
trading: {
enableTrading: true,
showOpenOrders: true,
showPositions: true,
},
contextMenu: {
showTradingOptions: true, // Show Buy/Sell in context menu
},
popups: {
showWelcome: false,
showTutorial: false,
},
favourite: {
symbols: ["AAPL", "GOOGL", "MSFT"],
},
// UI customization
exclude: {
leftPanel: false,
rightPanel: false,
topBar: false,
},
// Event callbacks
appCallback: ({ eventType, message, onClose }) => {
console.log("Event:", eventType, message);
},
onReady: (chartInstance) => {
console.log("Chart ready");
},
onError: (error) => {
console.error("Error:", error);
},
};
const chart = createChart("#chart", config);π Configuration Properties
Required Properties
datafeed
Type: Datafeed
Your datafeed implementation that provides market data to the chart.
const config = {
datafeed: myDatafeed, // Must implement Datafeed interface
// ... other required properties
};See Datafeed API for complete implementation details.
symbol
Type: string
Initial symbol to display (e.g., βAAPLβ, βBYBIT:FUTURE:BTCUSDTβ).
const config = {
symbol: "AAPL", // Stock symbol
symbol: "BYBIT:FUTURE:BTCUSDT", // Crypto futures
// ... other properties
};interval
Type: string
Initial time interval (e.g., β1mβ, β5mβ, β1Hβ, β1Dβ).
const config = {
interval: "1D", // Daily
interval: "1H", // Hourly
interval: "5m", // 5 minutes
// ... other properties
};Supported intervals: "1m", "5m", "15m", "30m", "1H", "4H", "1D", "1W", "1M"
licenseKey
Type: string
Your SDK license key.
const config = {
licenseKey: "YOUR_LICENSE_KEY",
// ... other properties
};Display Options
theme
Type: "light" | "dark"
Default: "light"
Chart theme.
const config = {
theme: "dark", // Dark theme
theme: "light", // Light theme
// ... other properties
};themeColor
Type: string
Default: undefined
Theme color for chart background (e.g., βdarkβ, β#1a1a1aβ).
const config = {
themeColor: "#1a1a1a", // Custom dark background
// ... other properties
};autosize
Type: boolean
Default: true
Enable automatic resizing.
const config = {
autosize: true, // Auto-resize with container
// ... other properties
};width
Type: number | string
Default: "100%"
Chart width - number in pixels or string with units.
const config = {
width: 800, // 800px
width: "100%", // Full width
width: "50vw", // 50% of viewport width
// ... other properties
};height
Type: number | string
Default: "100%"
Chart height - number in pixels or string with units.
const config = {
height: 600, // 600px
height: "100%", // Full height
height: "80vh", // 80% of viewport height
// ... other properties
};locale
Type: string
Default: "en-US"
Locale for internationalization (e.g., βen-USβ, βenβ).
const config = {
locale: "en-US", // English (US)
locale: "en", // English
// ... other properties
};Feature Flags
debugLog
Type: boolean
Default: false
Enable debug logging to console.
const config = {
debugLog: true, // Enable debug logs
// ... other properties
};disableSearch
Type: boolean
Default: false
Hide search bar in top bar.
const config = {
disableSearch: true, // Hide search bar
// ... other properties
};Use Cases:
- Fixed symbol charts
- Custom symbol selector
- Embedded dashboards
- Mobile optimization
disableCompare
Type: boolean
Default: false
Hide compare button in top bar.
const config = {
disableCompare: true, // Hide compare button
// ... other properties
};hideDrawingToolBar
Type: boolean
Default: false
Hide drawing toolbar in top bar.
const config = {
hideDrawingToolBar: true, // Hide drawing toolbar
// ... other properties
};alwaysDrawMode
Type: boolean
Default: false
Enable always draw mode.
const config = {
alwaysDrawMode: true, // Always in drawing mode
// ... other properties
};autoSave
Type: boolean
Default: true
Automatically save chart state to the browserβs sessionStorage and restore it when the page is reloaded or refreshed. When enabled, the following chart configuration is persisted:
- Chart layout β grid layout (single, split, multi-pane)
- Symbols & intervals β which symbols are loaded and their timeframes
- Indicators β all added indicators with their parameters
- Drawings β trendlines, Fibonacci, rectangles, and all other drawing objects
- Chart settings β chart type, appearance preferences
- Theme β light/dark mode and custom theme color
Note: This uses
sessionStorage, notlocalStorage. Session storage is scoped to the current browser tab β the saved state is automatically cleared when the tab or browser window is closed. It only persists across page refreshes within the same tab. Opening a new tab starts with a fresh chart from your configured props.
// Enabled by default β chart state persists across page refreshes
const chart = GoChartingSDK.createChart("#chart", {
datafeed: myDatafeed,
symbol: "AAPL",
interval: "1D",
licenseKey: "YOUR_KEY",
autoSave: true, // default
});
// Disable auto-save β always start fresh from props on every load
const chart = GoChartingSDK.createChart("#chart", {
datafeed: myDatafeed,
symbol: "AAPL",
interval: "1D",
licenseKey: "YOUR_KEY",
autoSave: false,
});Behavior:
- When
autoSave: true(default), the chart state is saved tosessionStorageafter initialization and whenever the user makes changes (adds indicators, draws objects, changes layout, switches theme, etc.) - On page refresh, the saved state is restored automatically β the chart picks up exactly where the user left it
- When
autoSave: false, the chart always initializes from the props you pass (symbol,interval,theme, etc.) with no persistence
Configuration Overrides
defaultInitialChartConfig
Type: DefaultInitialChartConfig
Default: undefined
Override default initial chart configuration. Applied after localStorage hydration to override chart settings.
const config = {
defaultInitialChartConfig: {
settings: {
showCrosshairPlusIcon: false,
zone: "America/New_York",
showGrid: true,
showVolume: true,
},
appearance: {
backgroundColor: "#1a1a1a",
grid: { enabled: true, color: "#2a2a2a" },
},
},
// ... other properties
};trading
Type: TradingConfig
Default: undefined
Trading configuration overrides. Controls the trading panel, order display, and trading behavior.
type TradingConfig = {
// Core Trading Settings
enableTrading?: boolean; // Enable trading panel features (default: false)
// UI Display Options
showReverseButton?: boolean; // Show reverse button in trading panel (default: true)
showOpenOrders?: boolean; // Show open orders panel (default: true)
showPositions?: boolean; // Show positions panel (default: true)
showExecutions?: boolean; // Show executions/trades panel (default: true)
showNotifications?: boolean; // Show trading notifications (default: true)
// Trading Behavior
beep?: boolean; // Play sound on order execution (default: true)
quickTradeMode?: boolean; // Enable quick trade mode (default: false)
// Take Profit Settings
enableTakeProfitDefaults?: boolean; // Enable take profit defaults (default: false)
defaultTakeProfitSpread?: number; // Default take profit spread (default: 1)
defaultTakeProfitSpreadType?: "tick" | "price" | "percent"; // Default: "tick"
// Stop Loss Settings
enableStopLossDefaults?: boolean; // Enable stop loss defaults (default: false)
defaultStopLossSpread?: number; // Default stop loss spread (default: 1)
defaultStopLossSpreadType?: "tick" | "price" | "percent"; // Default: "tick"
// Position Display Settings
boxAlignment?: "left" | "right"; // Trading box alignment (default: "right")
lineCategory?: "extended" | "compact"; // Order/position line category (default: "extended")
// Order Type Support
supportStopOrders?: boolean; // Enable Stop order options in context menus (default: false)
supportStopLimitOrders?: boolean; // Enable Stop-Limit order options in context menus (default: false)
};Example:
import { createChart } from "@gocharting/chart-sdk";
const chart = createChart("#chart", {
symbol: "AAPL",
interval: "1D",
datafeed: myDatafeed,
licenseKey: "YOUR_LICENSE_KEY",
trading: {
enableTrading: true,
showOpenOrders: true,
showPositions: true,
showExecutions: true,
beep: true,
enableTakeProfitDefaults: true,
defaultTakeProfitSpread: 10,
defaultTakeProfitSpreadType: "tick",
enableStopLossDefaults: true,
defaultStopLossSpread: 5,
defaultStopLossSpreadType: "tick",
supportStopOrders: true,
supportStopLimitOrders: true,
},
appCallback: ({ eventType, message, onClose }) => {
console.log("Trading event:", eventType, message);
},
});See Trading API for complete trading integration details.
contextMenu
Type: ContextMenuOptions
Default: { showTradingOptions: true }
Control the visibility of trading options in the right-click context menu.
type ContextMenuOptions = {
/** Show trading options (Buy/Sell buttons) in context menu */
showTradingOptions?: boolean; // Default: true
};Example:
// Hide trading options from context menu
const chart = createChart("#chart", {
symbol: "BTCUSDT",
interval: "1H",
datafeed: myDatafeed,
licenseKey: "YOUR_LICENSE_KEY",
contextMenu: {
showTradingOptions: false, // Hide Buy/Sell buttons
},
});Use Cases:
- View-Only Charts: Set to
falsefor charts where trading is not allowed - Demo Accounts: Hide trading options for educational or demo environments
- Compliance: Meet regulatory requirements for non-trading users
- Full Trading: Set to
true(default) for complete trading functionality
New in v1.0.47 π
popups
Type: PopupsConfig
Default: undefined
Popup display preferences.
const config = {
popups: {
showWelcome: false, // Hide welcome popup
showTutorial: false, // Hide tutorial popup
},
// ... other properties
};favourite
Type: FavouriteConfig
Default: undefined
Favorite symbols configuration.
const config = {
favourite: {
symbols: ["AAPL", "GOOGL", "MSFT", "AMZN"],
},
// ... other properties
};UI Customization
exclude
Type: ExcludeOptions
Default: undefined
Object to exclude specific UI elements or features.
const config = {
exclude: {
leftPanel: true, // Hide left panel
rightPanel: true, // Hide right panel
topBar: false, // Show top bar
},
// ... other properties
};Event Callbacks
appCallback
Type: AppCallbackEventHandler
Default: undefined
Callback for trading events and application-level events. Handles all chart events including trading, alerts, data downloads, and UI interactions.
const config = {
appCallback: ({ eventType, message, onClose }) => {
if (eventType === "PLACE_ORDER") {
const orderMsg = message as PlaceOrderMessage;
console.log("Order:", orderMsg.order);
} else if (eventType === "CREATE_ALERT") {
const alertMsg = message as AlertMessage;
console.log("Alert:", alertMsg.alert);
}
// Call onClose() to close dialogs if needed
},
// ... other properties
};See Events API for complete event handling details.
onReady
Type: OnReadyEventHandler
Default: undefined
Callback when chart is ready and initialized. Receives the ChartInstance (React component).
const config = {
onReady: (chartInstance) => {
console.log("Chart ready");
// chartInstance has all control methods
chartInstance.setSymbol("MSFT");
chartInstance.setBrokerAccounts(data);
},
// ... other properties
};This receives the ChartInstance (React component), NOT the ChartWrapper returned by createChart().
onError
Type: OnErrorEventHandler
Default: undefined
Callback for errors during chart initialization or operation.
const config = {
onError: (error) => {
console.error("Chart error:", error);
// Handle error (show notification, retry, etc.)
},
// ... other properties
};π‘ Usage Examples
Example 1: Basic Configuration
import { createChart } from "@gocharting/chart-sdk";
const chart = createChart("#chart", {
// Required
datafeed: myDatafeed,
symbol: "AAPL",
interval: "1D",
licenseKey: "YOUR_LICENSE_KEY",
// Display
theme: "dark",
width: "100%",
height: "600px",
});Example 2: Trading Platform Configuration
const chart = createChart("#chart", {
datafeed: myDatafeed,
symbol: "BYBIT:FUTURE:BTCUSDT",
interval: "1m",
licenseKey: "YOUR_LICENSE_KEY",
// Trading features
trading: {
enableTrading: true,
showOpenOrders: true,
showPositions: true,
showExecutions: true,
beep: true,
supportStopOrders: true,
supportStopLimitOrders: true,
enableTakeProfitDefaults: true,
defaultTakeProfitSpread: 10,
defaultTakeProfitSpreadType: "tick",
},
// Event handling
appCallback: ({ eventType, message, onClose }) => {
if (eventType === "PLACE_ORDER") {
// Handle order placement
placeOrder(message.order);
onClose(); // Close dialog
}
},
onReady: (chartInstance) => {
// Set broker accounts when ready
chartInstance.setBrokerAccounts(brokerData);
},
});Example 3: Embedded Dashboard Configuration
const chart = createChart("#chart", {
datafeed: myDatafeed,
symbol: "AAPL",
interval: "1D",
licenseKey: "YOUR_LICENSE_KEY",
// Clean UI for embedding
disableSearch: true, // Hide search bar
disableCompare: true, // Hide compare button
hideDrawingToolBar: true, // Hide drawing toolbar
// Exclude panels
exclude: {
leftPanel: true,
rightPanel: true,
},
// Custom settings
defaultInitialChartConfig: {
settings: {
showCrosshairPlusIcon: false,
zone: "America/New_York",
},
},
});Example 4: Multi-Language Configuration
const chart = createChart("#chart", {
datafeed: myDatafeed,
symbol: "AAPL",
interval: "1D",
licenseKey: "YOUR_LICENSE_KEY",
// Internationalization
locale: "en-US", // or "en", "es", "fr", etc.
// Theme
theme: "light",
themeColor: "#ffffff",
});Example 5: Custom Size and Appearance
const chart = createChart("#chart", {
datafeed: myDatafeed,
symbol: "AAPL",
interval: "1D",
licenseKey: "YOUR_LICENSE_KEY",
// Size
width: 1200,
height: 800,
autosize: false, // Disable auto-resize
// Appearance
theme: "dark",
themeColor: "#1a1a1a",
// Settings override
defaultInitialChartConfig: {
settings: {
showGrid: true,
showVolume: true,
},
appearance: {
backgroundColor: "#1a1a1a",
grid: { enabled: true, color: "#2a2a2a" },
},
},
});Example 6: Debug Mode
const chart = createChart("#chart", {
datafeed: myDatafeed,
symbol: "AAPL",
interval: "1D",
licenseKey: "YOUR_LICENSE_KEY",
// Enable debug logging
debugLog: true,
// Error handling
onError: (error) => {
console.error("Chart error:", error);
// Show user-friendly error message
showErrorNotification(error);
},
});π Related Documentation
- Chart API - Chart creation with
createChart() - Chart Widget API - ChartInstance methods
- Datafeed API - Implement custom data sources
- Trading API - Trading integration
- Events API - Event handling
- TypeScript Types - Type definitions
For complete working examples, see the Examples section.