|
Unable to Zoom Finance Chart |
Posted by Aishwarya on Sep-16-2015 19:28 |
|
Hello,
I am not able to zoom finance chart OnMouseWheel scroll. I am making use of
chartdir60.lib. I have followed the instruction given is the below link:
http://www.chartdir.com/forum/download_thread.php?
bn=chartdir_support&pattern=&thread=1377713024
and it was crashing at setChartMetrics(chartMetrics).
when i have commented the above line, i was able to get the chart zoomed once and was
not able to zoom further. Please do find the attached and suggest the solution for the
problem.
|
Re: Unable to Zoom Finance Chart |
Posted by Peter Kwan on Sep-17-2015 01:54 |
|
Hi Aishwarya,
The issue is because your code is memory that are out of scope.
In C#, memory management is automatic. In C++, your code must manage the memory.
So when using C# code in C++, your code needs to ensure all the memory is allocated
properly and is not deleted or out of scope.
In the drawChart routine, the FinanceChart is allocated as a local stack variable. So it is
automatically destroyed when the code returns from drawChart. If you set the pointer to
the FinanceChart to the CChartViewer (using viewer->setChart), the pointer will become
invalid when the drawChart returns, so the code will crash in any future event that uses
the FinanceChart. To solve the problem, please allocate the FinanceChart in the heap
instead so that it can exist outside the scope of drawChart. For example, you can use:
FinanceChart *m = new FinanceChart(....);
Note that your code must also delete the unused FinanceChart to avoid memory leak. For
example, before your use viewer->setChart to set the FinanceChart to the CChartViewer,
remember to delete the previous chart:
delete viewer->getChart();
viewer->setChart(m);
Also, when your program ends or when the window closes, you may want to delete the
last FinanceChart still in the CChartViewer to avoid memory leak.
Hope this can help.
Regards
Peter Kwan |
|