GetObjectName

Returns the name of a chart object by its index.

Syntax

GetObjectName(index: number, isStatic: boolean = false): string

Parameters

Parameter
Type
Description

index

number

The index of the object

isStatic

boolean

Optional. Whether to look in static objects (default: false)

Return Value

Returns a string representing the object's name.

Description

The GetObjectName method retrieves the name of a chart object based on its index in the list of objects. Objects are indexed from 0 to GetObjectCount() - 1. This method is useful for iterating through all objects on a chart.

Example

// Get name of first object
const firstName = this.api.GetObjectName(0)
console.log(`First object name: ${firstName}`)

// Get name of first static object
const firstStaticName = this.api.GetObjectName(0, true)
console.log(`First static object name: ${firstStaticName}`)

// List all objects
const count = this.api.GetObjectCount()
for (let i = 0; i < count; i++) {
    const name = this.api.GetObjectName(i)
    const type = this.api.GetObjectType(name)
    console.log(`Object ${i}: Name=${name}, Type=${type}`)
}

// List all static objects
const staticCount = this.api.GetObjectCount(true)
for (let i = 0; i < staticCount; i++) {
    const name = this.api.GetObjectName(i, true)
    const type = this.api.GetObjectType(name, true)
    console.log(`Static object ${i}: Name=${name}, Type=${type}`)
}

Last updated