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

Message ListMessage List     Post MessagePost Message

  Issue of plotting line in LineLayer
Posted by Takeshi on Apr-21-2018 14:37
Attachments:
Hi Peter,

I have an array "m_swingpointData" carrying a series of high and low price. I am trying to plot it with LineLayer in mainChart.

As shown in the attached image, there should have a low point outside the chart, but somehow it does not show up any line between the first point in chart(Labelled as 3.55) and the preceding point which is outside the chart. I have checked ensuring that the preceding point has been included in the array.

My code is amended based on your financedemo sample code in Qt so I think the definition of the FinanceChart and mainchart should be similar.

DoubleArray scatterSP = DoubleArray(m_swingpointData, m_noOfPoints);
LineLayer *sp_layer=mainchart->addLineLayer();
sp_layer->addDataSet(scatterSP,0xcf4040, "")->setDataSymbol(Chart::CircleShape, 4);
sp_layer->setLineWidth(3);
sp_layer->setGapColor(Chart::SameAsMainColor);

Please help and thank you very much for your time in advance.


Best Regards,
Takeshi
Capture.PNG

  Re: Issue of plotting line in LineLayer
Posted by Peter Kwan on Apr-21-2018 22:42
Hi Takeshi,

In the current implementation of the FinanceChart, the first "extra_points" of data are simply removed before plotting, so points are that outside the chart no longer exist when the line is drawn.

For your case, for the point that is outside the chart, you would need to interpolate the position of the line at the left edge of the plot area. You may then add the line segment back using an extra data set. (Using an extra dataset is to ensure the extra line segment
will not create a extra symbol at the edge.)

I have not tested myself, but I think the code is like:

// find the point outside the left edge of the plot area
int outside = -1;
for (outside = extraPoints - 1; outside >= 0; --i)
    if (m_swingpointData[outside] != Chart::NoValue) break;

if ((outside >= 0) && (m_swingpointData[extraPoints] == Chart::NoValue))
{
    // find the first point inside the plot area
    for (int i = extraPoints + 1; i < m_noOfPoints; ++i)
    {
        if (m_swingpointData[i] != Chart::NoValue)
        {
            // interpolate the point at the edge
            m_swingpointData[extraPoints] = (m_swingpointData[outside] * (i - extraPoints) + m_swingpointData[extraPoints] * (extraPoints - outside)) / (i - outside);

            // add an extra segment without a data symbol
            sp_layer->addDataSet(DoubleArray(m_swingpointData, i + 1), 0xcf4040);

            // restore original value in case your code needs to use m_swingpointData later
            m_swingpointData[extraPoints] = Chart::NoValue;
            break;
        }
    }
}

Regards
Peter Kwan

  Re: Issue of plotting line in LineLayer
Posted by Takeshi on Apr-22-2018 13:06
Hi Peter,

Thank you very much for your inspiring input, the idea works well!


Best Regards,
Takeshi