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

Message ListMessage List     Post MessagePost Message

  Draw line in finance chart
Posted by Nidhi on Oct-28-2015 23:36
Attachments:
I am drawing lines in finance chart which is working with scrolling and zoomin and
zoomout.

Lines are drawing fine but when I scroll chart line left stable where its drawn.

I am attaching 2 images here:
line: here line is drawing well according to coordinate I select but its not moving with
scrolling or zoom.

Line line = m.addLine(Convert.ToInt32(xdata[0]), Convert.ToInt32(ydata[0]),
Convert.ToInt32(xdata[xdata.Count - 1]), Convert.ToInt32(ydata[ydata.Count - 1]),
0x000040, 2);

linelayer: Its moving well with scrolling and zoom but its not drawing according to
coordinate.


if (xdata.Count > 0)
            {
                XYChart c = (XYChart)m.getChart(0);

                LineLayer layer = c.addLineLayer();
                Double[] Yval = new Double[viewPortTimeStamps.Length];
                DateTime[] Xval = new DateTime[viewPortTimeStamps.Length];

                viewPortTimeStamps.CopyTo(Xval, 0);

                for (int i = 0; i < xdatapoint.Count; i++)
                {
                    int Index = (int)Math.Floor(Chart.bSearch(viewPortTimeStamps,
xdatapoint[i]));
                    Yval[Index] = viewPortDatacloseData[Index];
                }
                layer.addDataSet(Yval, 0x000040);
                //layer.setXData(Xval);
                layer.setFastLineMode();
                layer.setLineWidth(2);

            }
linelayer.PNG
line.PNG

  Re: Draw line in finance chart
Posted by Peter Kwan on Oct-30-2015 00:24
Hi Nidhi,

From your description, I assume you mean the "addLineLayer" method works correctly, while
the "addLine" method does not move the line when the chart is scrolled.

The "addLine" method is based on pixel coordinates, not data values. It will not affect by
the data values on the chart. So even if you scroll the chart, line will still be in the same
pixel coordinate there.

If the input you use to create the line are pixel coordinates (such as if they come from
mouse coordinates), you would need to convert them to data values, and then use the
addLineLayer method to add them.

You may refer to the programmable track cursors sample code for some examples on how to
obtain the data values from the mouse coordinates. For example, in the "Finance Chart
Track Line" sample code, the code can determine the timestamp at the mouse cursor
position. In the "Track Line with Axis Labels" sample code, the code can determine the y
data value of the from the mouse y coordinates.

Hope this can help.

Regards
Peter Kwan

  Re: Draw line in finance chart
Posted by Nidhi on Oct-30-2015 18:02
Do you have any example for using d.line function in track cursor as its not working well
here  ?

  Re: Draw line in finance chart
Posted by Peter Kwan on Oct-31-2015 04:24
Hi Nidhi,

The original "Finance Chart Track Line" sample code uses the d.vline method as follows:

d.vline(plotAreaTopY, plotAreaTopY + plotArea.getHeight(), c.getXCoor(xValue) +
                    c.getAbsOffsetX(), d.dashLineColor(0x000000, 0x0101));

The above is equivalent to the d.line method:

d.line(c.getXCoor(xValue) + c.getAbsOffsetX(), plotAreaTopY, c.getXCoor(xValue) +
   c.getAbsOffsetX(), plotAreaTopY + plotArea.getHeight(), d.dashLineColor(0x000000,
0x0101));

So to get an example, you may start with the original "Finance Chart Track Line" sample
code below, and replace the d.vline and d.line. In this way, you can get an example using
d.line.

http://www.advsofteng.com/doc/cdnet.htm#trackfinance.htm

Regards
Peter Kwan