fontSize: number - Optional. The font size (default: 14)
fontName: string - Optional. The font name (default: 'Roboto Flex')
fontColor: string - Optional. The font color (default: '#000000')
isStatic: boolean - Optional. Whether the object is static (default: false)
Return Value
Returns boolean - true if the text was set successfully, false otherwise.
Description
The SetObjectText method sets the text content and formatting properties for a specified chart object. This method is primarily used with text-based objects like labels, but can also be used with other objects that support text properties.
// Set basic text
const success1 = this.api.SetObjectText("MyLabel", "Hello World");
console.log(`Text set: ${success1}`);
// Set text with custom formatting
const success2 = this.api.SetObjectText(
"MyLabel",
"Custom Text",
14, // font size
"Arial",
0xff0000 // red color
);
console.log(`Formatted text set: ${success2}`);
// Set text for a static object
const success3 = this.api.SetObjectText(
"MyStaticLabel",
"Static Text",
12,
"Verdana",
0x0000ff, // blue color
true // isStatic
);
console.log(`Static text set: ${success3}`);
// Update multiple text objects
const textObjects = ["Label1", "Label2", "Label3"];
for (let i = 0; i < textObjects.length; i++) {
this.api.SetObjectText(
textObjects[i],
`Text ${i + 1}`,
10 + i * 2, // increasing font size
"Arial"
);
}