It may sometimes be necessary to take additional actions when a study is removed (closed) from a chart; like saving studies in an external database for retrieval at a later time.

To export or import studies, the following methods can be used:



With CIQ.ChartEngine.addEventListener, you can register a callback to catch changes as they happen and export the layout like so:

var listener = function(parameters) {
    var myData = stxx.exportLayout();
    // Do other stuff...
stxx.addEventListener("layout", listener);

layout events occur whenever the user adds, deletes or resizes a panel, modifies drawings, or changes the chartType.


An alternative method would be to utilize the injection API. Injecting a new removeStudy function would allow you to include a call to your database every time any panel is removed. Here you can deal with both study overlays and study panels being removed:

// Removes a study from the chart (and panel if applicable)
// @param  {object} stx A chart object
// @param  {object} sd  A study descriptor returned from CIQ.Studies.quickAddStudy or CIQ.Studies.go
// @memberof CIQ.Studies
CIQ.Studies.removeStudy=function(stx, sd){
    if(sd.libraryEntry && sd.libraryEntry.overlay){
        var panel=stx.panels[sd.panel];