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

Message ListMessage List     Post MessagePost Message

  Vertical Zoom on Finance Chart
Posted by Andrea on Jan-20-2014 19:04
Hi Peter,

I implemented zooming with the mouse scrool as your example.

Now I have a problem, I can not do only vertical zoom when I drag the mouse in the
vertical y-axis. I set and update the view port as in your examples, but only vertically.
I expect that the graph increases or decreases in height, but it does not work.

thsi is the code:

void CMWChart::VerticalZoom(QMouseEvent* event)
{

  // // We zoom in or out by 10% depending on the mouse wheel direction.
double newVpHeight = m_pChartViewer->getViewPortHeight() * ((event->y() -
m_lastYMousePos) > 0 ? 0.9 : 1 / 0.9);

    // We do not zoom beyond the zoom width or height limits.
    newVpHeight = max(m_pChartViewer->getZoomInHeightLimit(), min(newVpHeight,
        m_pChartViewer->getZoomOutHeightLimit()));

    if ((newVpHeight != m_pChartViewer->getViewPortHeight()))
    {

        double deltaY = (m_pChartViewer->getPlotAreaMouseY() - m_pChartViewer->
getPlotAreaTop()) *
            (m_pChartViewer->getViewPortHeight() - newVpHeight) / m_pChartViewer->
getPlotAreaHeight();
        m_pChartViewer->setViewPortTop(m_pChartViewer->getViewPortTop() + deltaY);
        m_pChartViewer->setViewPortHeight(newVpHeight);

        m_pChartViewer->updateViewPort(true, false);
}
}

Can you help me?

Thanks.

  Re: Vertical Zoom on Finance Chart
Posted by Peter Kwan on Jan-21-2014 02:52
Hi Andrea,

Your VerticalZoom code should have set the vertical view port to reflect zoom in/out. Have
you also configured your chart to synchronize the y-axis with the vertical view port?

After modifying the view port (which reflects mouse actions), you would still need to specify
how should the chart be affected. For example, in a FinanceChart object, there can be
multiple charts (main price chart, indicator charts, etc). In the main price chart, depending
on how you configure the chart, there can also be two y-axes for the prices and for the
volume. You would need to tell ChartDirector which y-axis (or axes) in which chart(s) you
would like to synchronize with the changing view port?

For example, if you would like to zoom into the price axis or the main price chart, please add
the followng code when you set up the main price chart:

    // Your existing code that configures the main price chart. We save the returned
    // XYChart object pointer to a variable so we can use it later.
    XYChart *myChart = c->addMainChart(...);

    m_pChartViewer->syncLinearAxisWithViewPort("y", myChart->yAxis());
    myChart->yAxis()->setMargin(0, 0);

    // If you do not already have the setClipping line, you may want to add it here.
    myChart->setClipping();

Hope this can help.

Regards
Peter Kwan

  Re: Vertical Zoom on Finance Chart
Posted by Andrea on Jan-29-2014 17:44
Attachments:
Hi Peter,
thanks for your support.

With your help i'm able to zoom vertically.

But i have another problem:
now when i zoom horizontally, i must find max, min and number of prices based on to
candles that will be displayed in the chart.
I have finded this, but i'm not able to set the viewport for correct visualization.
the candles come out of the plot area or do not appear all prices.

I attach an example before and after the horizontal zoom.
This my code to zoom:

void CMWChart::SL_onMouseWheel(QWheelEvent* event)
{
// Process the mouse wheel only if the mouse is over the plot area
if (!m_pChartViewer->isMouseOnPlotArea())
    {
        event->ignore();
        return;
    }

    // We zoom in or out by 10% depending on the mouse wheel direction.
double newVpWidth = m_pChartViewer->getViewPortWidth() * (event->delta() > 0
? 0.9 : 1 / 0.9);


    // We do not zoom beyond the zoom width or height limits.
    newVpWidth = max(m_pChartViewer->getZoomInWidthLimit(), min(newVpWidth,
        m_pChartViewer->getZoomOutWidthLimit()));

    if ((newVpWidth != m_pChartViewer->getViewPortWidth()))
    {
        // Set the view port position and size so that the point under the mouse remains
under
        // the mouse after zooming.

        double deltaX = (m_pChartViewer->getPlotAreaMouseX() - m_pChartViewer-
>getPlotAreaLeft()) *
            (m_pChartViewer->getViewPortWidth() - newVpWidth) / m_pChartViewer-
>getPlotAreaWidth();
        m_pChartViewer->setViewPortLeft(m_pChartViewer->getViewPortLeft() + deltaX);
        m_pChartViewer->setViewPortWidth(newVpWidth);


double l_minYVisibleValue = 0,l_MaxYVisibleValue = 0;
int l_startXIndex = 0;
int l_extraDays = 0;

//With this i find x axis data
int l_XnofVisiblePoints = GetXnOfVisiblePoints(l_startXIndex,l_extraDays);
//With this i find y axis data based on x axis
int l_YnofVisiblePoints =
GetYnOfVisiblePoints(l_startXIndex,l_XnofVisiblePoints,l_minYVisibleValue,l_MaxYVisibleValu
e);

//??????
m_pChartViewer->setViewPortHeight((double)l_YnofVisiblePoints/m_pChartViewer-
>getValueAtViewPort("y",m_pChartViewer->getViewPortHeight()));
m_pChartViewer->setViewPortTop(l_MaxYVisibleValue/m_maxPriceDataSeries);
//??????

m_pChartViewer->updateViewPort(true, false);
    }

}

Can you help me?

Many thanks.
Chart.PNG
Chart2.PNG
Chart3.PNG

  Re: Vertical Zoom on Finance Chart
Posted by Peter Kwan on Jan-30-2014 03:28
Hi Andrea,

If you zoom in vertically, it is normal that some of the candlesticks may flow outside the
plot area. If you want the candlesticks to always be within the plot area, it means you
cannot allow the user to zoom in vertically. If you latter is what you need, you just need to
disable vertical zooming. ChartDirector will then automatically scale the y-axis to fit your
data.

If you want to allow the user to vertically zoom sometimes, and let ChartDirector
automatically determine the y-axis scale at other times, you can design your code not to
call "syncLinearAxisWithViewPort" when you do not want to allow the user to zoom in
vertically, or you can set the view port top to 0, view port height to 1, and then call
setFullRange("y", 0, 0) to reset the vertical zooming,

Hope this can help.

Regards
Peter Kwan