GetChartInformation
Returns information about the current chart state and properties.
Syntax
GetChartInformation(): TChartInfo | nullReturn Value
Returns a TChartInfo object containing chart information, or null if the operation fails.
Description
The GetChartInformation method provides detailed information about the current chart state, including visible bar indices, paint rectangle dimensions, bar width, and current zoom level. This information is useful for indicators that need to understand the chart's visual state and coordinate system.
The returned TChartInfo object contains the following properties:
firstIndex- Index of the leftmost visible bar on the chartlastIndex- Index of the rightmost visible bar on the chartpaintRect- Rectangle defining the chart's paint areabarWidth- Width of each bar in pixelscurrZoom- Current horizontal zoom level
Example
// Get chart information
const chartInfo = this.api.GetChartInformation()
if (chartInfo) {
// Check if chart has valid indices
if (chartInfo.firstIndex >= 0 && chartInfo.lastIndex >= 0) {
// Process only visible bars
for (let i = chartInfo.firstIndex; i <= chartInfo.lastIndex; i++) {
// Your indicator logic here
}
}
// Access chart properties
console.log(`Visible bars: ${chartInfo.firstIndex} to ${chartInfo.lastIndex}`)
console.log(`Bar width: ${chartInfo.barWidth} pixels`)
console.log(`Current zoom: ${chartInfo.currZoom}`)
console.log(`Paint area: ${chartInfo.paintRect.width}x${chartInfo.paintRect.height}`)
}
// Check for zoom level before processing
const chartInfo = this.api.GetChartInformation()
if (chartInfo && chartInfo.currZoom <= 2) {
// Skip processing when zoomed out too much
return
}Last updated