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

Message ListMessage List     Post MessagePost Message

  Draw track lines in a multichart
Posted by C.H.Wang on Nov-18-2015 15:56
Attachments:
Hello!

  I merge two FinanceChart objects with multichart and I want to know how to tracking the whole multichart.
The attached file is my code(C#).
My program failed on executing trackFinance.
could you tell me how to draw track lines in a  multichart? Thanks!


Regard
C.H.Wang
program.docx
program.docx

57.48 Kb

  Re: Draw track lines in a multichart
Posted by Peter Kwan on Nov-19-2015 03:38
Hi C.H.Wang,

You may already be aware that the FinanceChart itself it a MultiChart. It is a MultiChart
that contains multiple XYChart objects for the main price chart and the indicator charts.

If you put two FinanceChart objects into a MultiChart, it means you are use one
MultiChart to contain two other MultiChart objects, which in turn contain multiple
XYChart objects.

For Programmable Track Cursors, the track line should be drawn in the chart object that
set to the WinChartViewer, which is the top-level MultiChart. In your case, the top-level
MultiChart is not a FinanceChart but contains multiple FinanceChart objects. To handle
this, instead of calling:

//Draw a track line for a FinanceChart, which is the chart in the WinChartViewer
trackFinance(((MultiChart)viewer.Chart, mouseX);

the code can be modified to:

//This is the chart displayed in the WinChartViewer
MultiChart m = (MultiChart)viewer.Chart;
Drawarea d = m.initDynamicLayer();

//Draw the track line of the FinanceChart on the top-level MultiChart dynamc layer
for (int i = 0; i < m.getChartCount(); ++i)
    trackFinance(d, (MultiChart)m.getChart(i), mouseX);


The original trackFinance code:

        private void trackFinance(MultiChart m, int mouseX)
        {
            // Clear the current dynamic layer and get the DrawArea object to draw on it.
            DrawArea d = m.initDynamicLayer();

            .......
        }

should be modified to:


        private void trackFinance(DrawArea d, MultiChart m, int mouseX)
        {
            .......
        }

Hope this can help.

Regards
Peter Kwan

  Re: Draw track lines in a multichart
Posted by C.H.Wang on Nov-19-2015 11:23
Thanks for your reply.

I get the error message "InvalidCastException" while getting xValue as follows.

       private void trackFinance(MultiChart m, int mouseX)
        {
           ....

            // Get the data x-value that is nearest to the mouse
            int xValue = (int)(((XYChart)m.getChart(0)).getNearestXValue(mouseX));

           ....


It can't convert 'ChartDirector.FinanceChart' to 'ChartDirector.XYChart'。

Regards
C.H.Wang

  Re: Draw track lines in a multichart
Posted by Peter Kwan on Nov-19-2015 23:20
Hi C.H. Wang,

The error probably means that the chart "m" is not a FinanceChart.

According to your previous post, you have a MultiChart that contains two FinanceChart
objects. So the MultiChart is not a FinanceChart, but is a container for FinanceChart
objects. Are you pass that MultiChart (which is not a FinanceChart) to traceFinance. This
would cause the error because as explained above, that MultiChart is not a FinanceChart.

In the code in my previous post, I suggest to pass (MultiChart)m.getChart(i) to
traceFinance, which is the chart contained in the MultiChart, and according to your
description, the MultiChat contains FinanceChart objects.

Hope this can help.

Regards
Peter Kwan

  Re: Draw track lines in a multichart
Posted by C.H.Wang on Nov-20-2015 10:49
Hi Peter:
   Thank you very much. It works.