3.9.1Callback from ChartChange()

ChartChange() has an optional callback which fires with a response from each applicable/affected chart. For example:

// Some change to all visible charts…

Framework.ChartChange({

mode: "all",

}, function (MsgResponse) {

// Will be called with a separate MsgResponse from each visible chart.

// If there are no visible charts, there will be no callback(s)!

});

The response object has a result:{} which contains either success: true or success: false. If unsuccessful, there will be a textual error property describing the problem. For example:

// Load EMA(10) onto the active chart

Framework.ChartChange({

mode: "active",

command: "load-indicator",

indicator: "EMA",

indicatorSettings: {period: 10}

}, function (MsgResponse) {

// (Note: no callback if there is no active chart)

if (MsgResponse.result.success) {

// EMA has been loaded onto the chart

} else {

// EMA failed to load

// Error condition is in MsgResponse.result.error

}

});

The callback can also provide information which is required for subsequent calls to ChartChange(). For example, create-drawing returns the ID of the new drawing, which is required in order to modify or remove the drawing:

// Add a horizontal-line drawing to the chart, and get its ID for later use

Framework.ChartChange({

mode: "active",

command: "create-drawing",

drawing: {

type: "horizontalLine",

points: [{value: 1.17}],

text: "Hello",

style: {line: {color: "red"}}

}

}, function (MsgResponse) {

// (Note: no callback if there is no active chart)

if (MsgResponse.result.success) {

// Drawing has been created

// ID of the new drawing is in MsgResponse.result.drawingId

} else {

// Failed to create drawing

// Error condition is in MsgResponse.result.error

}

});