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:

exportLayout();

importLayout();

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.

Injections

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){
        stx.removeOverlay(sd.name);
        stx.draw();
    }else{
        var panel=stx.panels[sd.panel];
        if(panel)
            stx.panelClose(panel);
    }
};