ASE Home Page Products Download Purchase Support About ASE
ChartDirector Support
Forum HomeForum Home   SearchSearch

Message ListMessage List     Post MessagePost Message

  Synchronising x-axis of addcomparison() with FinanceChart
Posted by Takeshi on Oct-23-2021 15:05
Hi Peter,

Currently I am using Qt C++ to draw a FinanceChart with a compared dataset using addComparison function. The compared dataset m_compareData has a number of data points lesser than the FinanceChart HLOC. Should I need to deliberately find out which dates the m_compareData has missed out and assign Chart::NoValue to the missing dates, or is there any function that can directly synchronise the x-axis?

Many thanks in advance!

Best Regards,

  Re: Synchronising x-axis of addcomparison() with FinanceChart
Posted by Peter Kwan on Oct-24-2021 15:42
Hi Takeshi,

There is no built-in method synchronize data arrays with different dates.

If you compare the stock prices from two different exchanges (eg. Tokyo exchange with New York exchange), even if the arrays are of the same size, their dates may not be the same, because they have different national holidays, and the dates may be affected by unpredictable natural phenomena. (For example, in Hong Kong, if there is a typhoon, the trading day will be cancelled.)

To compare the stock prices, the compare data may need to be adjusted as follows:

(a) If a date exists in the main data, but not the compare data, an artificial value must be created. That value can be set to the value of the last closing price. (Most people expect a "price" means the the "last known price".) You can also set it to Chart::NoValue.

(b) If a date exists in the compare data, but not the main data, ignore the compare data.

Since the time stamps are sorted, so it is easy to adjust them. I have just written some code below (I have not tested it yet.) that adjust the compare data. The timeStamps and compareTimeStamps should only contain the date part (the time set to 00:00:00), to make sure they match exactly if their dates are the same.

The following are some code I just write down to illustrate the idea. (Note: I have not tested the code.)

// array to hold the adjusted compare data
double *adjustedCompareData = new double[timeStamps.len];

int n = 0;
for (int i = 0; i < timeStamps.len; ++i) {
    if (n >= compareTimeStamps_length)
         // compare data exhausted - fill rest with NoValue
         adjustedCompareData[i] = Chart::NoValue;
    else if (timeStamps[i] < compareTimeStamps[n])
         // date not exist in compare data, fill with last data value
         adjustedCompareData[i] = (i > 0) ? adjustedCompareData[i - 1] : Chart::NoValue;
    // if date exists, copy the data value, otherwise skip the data value
    else if timeStamps[i] == compareTimeStamps[n++]) {
         adjustedCompareData[i] = compareTimeData[n];

Best Regards,
Peter Kwan