|
ScatterLayer on a Finance Chart. |
Posted by GCain on Dec-22-2011 08:30 |
|
Hi,
I am trying to add some indicators onto a Finance chart at specific X Y points.
The finance chart draws correctly (image1) but when I add a scatter layer (code below)
the chart ends up looking like image2. The scatterlayer gets added
later; ie. When the user decides; usually after the chart has been rendered.
--//Code--
double Xvalues[mySignals.count()];
double Yvalues[mySignals.count()];
char *labels[mySignals.count()];
for(int i=0;i<mySignals.count();i++){
QStringList rec = mySignals.value(i).split("|");
QDateTime dateTime;
/* choose correct date format */
if(rec.value(0).lenth() == 8){
dateTime = QDateTime::fromString(rec.value(0),"yyyyMMdd");
}else{
dateTime = QDateTime::fromtime_t(rec.value(0).toDouble());
}
if(rec.value(2) != ""){
Xvalues[i] = QDateTimeToChartTime(dateTime);
Yvalues[i] = rec.value(1).toDouble();
labels[i] = rec.value(0).toLocal8Bit().data();
}else{
Xvalues[i] = QDateTimeToChartTime(dateTime);
Yvalues[i] = Chart::NoValue;
labels[i] = NULL;
}
}
ScatterLayer *buylayer = myMainChart->addScatterLayer(DoubleArray(Xvalues,sizeof(Xvalues)/sizeof(Xvalues[0])),
DoubleArray(Yvalues,sizeof(Yvalues)/sizeof(Yvalues[0])),
"ALERT", Chart::CircleSymbol, 10, 0xFFFFFF, 0x000000);
/* myMainChart gets created when the
original finance chart is rendered like this;*/
myMainChart = c->addMainChart(((this->parentWidget()->height()-40)-220)-(delHeight));
--//Code//--
I am using Qt 4.7 with MingW 4.4 on W7.
The problem appears to be stemming from the X-axis not being in scale, but I can't work
out where I am going wrong.
Thanks in advance!
|
Re: ScatterLayer on a Finance Chart. |
Posted by GCain on Dec-22-2011 09:46 |
|
Hi Peter,
I changed the Xvalues[] array to represent 0-mySignals.count(); and everything lines up.
Originally I was using the date which appears to be incorrect.
So I guess this has been solved unless you can see I am using the component incorrectly or
there is a better way to achieve this.
Kind Regards,
GCain.
ps. Great product, unbelievable support. Thanks. |
Re: ScatterLayer on a Finance Chart. |
Posted by Peter Kwan on Dec-23-2011 01:22 |
|
Hi GCain,
You are absolutely correct. For a FinanceChart (as well as any chart that uses a label based x-axis), the x-coordinate is 0, 1, 2, 3, .... for the first, second, third, fourth point ....
Regards
Peter Kwan |
|