|
Problem with drawing lines on a Finance Chart |
Posted by Paul on Jan-05-2011 00:56 |
|
I'm trying to draw lines on a Finance Chart, using a Line Layer:
FinanceChart *c = new FinanceChart(width);
c->setData(DoubleArray(Timestamps,numData),...);
XYChart* mc = c->addMainChart(CHART_HEIGHT);
...
LineLayer *ll = mc->addLineLayer(DoubleArray(Ycoords,numLines),Linecolor,"Lines");
ll->setXData(DoubleArray(Xcoords,numLines));
The setXData Function is for setting arbitrary X coordinates, but that's what's giving me trouble. The "Xcoords" array contains coordinates similar to the "Timestamps" array of the Finance chart. The lines in the LineLayer are drawn with correct Y scale - the prices data - but a wrong X scale that does not match the time scale of the Finance Chart.
How can I draw lines on a Finance Chart between arbitrary prices and dates? |
Re: Problem with drawing lines on a Finance Chart |
Posted by Peter Kwan on Jan-05-2011 01:56 |
|
Hi Paul,
In a standard financial chart, the timestamps are just arbitrary names, and are for human reading only. They are not the x-coordinates. The x-coordinates are the trading session number, which is just integers starting from 0, 1, 2, 3, 4 .....
In fact, you do not need to use x-coordinates at all. (If you are familiar with technical indicators, there is no need to use x-coordinates to compute any technical indicator.) You just need to the Ycoords array, which contain the points you want to plot. The Ycoords array should be of the same length as all other arrays in your code (eg. the same length as the closePrice array).
If you do not have data points in certain positions, please use Chart::NoValue to fill that position. Then in your code, please use:
LineLayer *ll = mc->addLineLayer(DoubleArray(Ycoords,numData),Linecolor,"Lines");
ll->setGapColor(Chart::SameAsMainColor); //jump through the NoValue points
If you must use the setXData method, it is OK so long as the x-coordinates are tradng session numbers. Please note like any other data series in a FinanceChart object, the first extraPoints (the extraPoints parameter in setData) will not be plotted.
Hope this can help.
Regards
Peter Kwan |
Re: Problem with drawing lines on a Finance Chart |
Posted by Paul on Jan-05-2011 02:14 |
|
Ok thanks, that makes sense. I'll translate the dates to bar numbers then. |
|