Adding custom data to dataSet

It is possible to embed custom data into the DataSet for use as future input for rendering custom output.

This is an example of how to leverage existing study calculation functions to add 3 additional data point to each sataSet instance. But you can use the same process with your own calculation functions.

To do this, a callback function must be created and included as the last argument for the newChart() function used to display your initial chart on. The call back function will be executed after the chart is created for the first time and can be used to perform additional operations.

The following code snippet illustrates how this is done.

When designing your main chart page, include an 'onLoad' event to display your chart once the HTML components have been rendered:

<body onLoad="displayChart()">

Later on in your code, you need to define the target function as follows:

function displayChart(){

     var sd1=new STX.Studies.StudyDescriptor("data_array_1", "ma", stxx.chart.panel,{"Period":20,"Field":"field","Type":"ma"},{"MA":"yellow"});
     sd1.chart=stxx.chart;
     sd1.days=parseFloat(sd1.inputs["Period"]);
     STX.Studies.calculateMovingAverageExponential(stxx,sd1);

     var sd2=new STX.Studies.StudyDescriptor("data_array_2", "ma", stxx.chart.panel,{"Period":50,"Field":"field","Type":"ma"},{"MA":"yellow"});
     sd2.chart=stxx.chart;
     sd2.days=parseFloat(sd2.inputs["Period"]);
     STX.Studies.calculateMovingAverageExponential(stxx,sd2);

     var sd3=new STX.Studies.StudyDescriptor("data_array_3", "ma", stxx.chart.panel,{"Period":300,"Field":"field","Type":"ma"},{"MA":"yellow"});
     sd3.chart=stxx.chart;
     sd3.days=parseFloat(sd3.inputs["Period"]);
     STX.Studies.calculateMovingAverageExponential(stxx,sd3);

}

Now, each element in the dataset array (stxx.chart.dataSet) would resemble something like this:

Adj_Close: 107.82
Close: 107.82
DT: Fri Sep 30 2011 00:00:00 GMT-0400 (EDT)
Date: "2011-09-30"
High: 110.01165709235528
Low: 107.74376844896155
MA data_array_1: 111.37982973662554    // custom data point
MA data_array_2: 113.97794507587781 //custom data point
MA data_array_3: 114.678886555 //custom data point
Open: 109.05876270437471
Result Intraday Mtm (20): 48.932310462462276
Volume: 288392300

You can iterate through the dataSet array and target each 'MA data_array_x' as needed to render your custom chart.

Note that if all you are trying to do is to create a complete custom study, this method is not recomended. Instead follow this link for a tutorial on how you to create a custom study: http://chartiq.com/licensing/documentation/#toc55