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

Message ListMessage List     Post MessagePost Message

  drawing horizontal lines that stop at start
Posted by dave on Jan-10-2023 11:18
Attachments:
hi Peter,
Hopefully this question makes sense. I have a finance chart. I need to draw a horizontal line across the premarket high and low, but only for a given day.

When a new day starts, a different line needs to be drawn. I can't quite get it figured out.

I know I can use mainChart.yAxis().addMark(...) but that draws a line across the entire chart.

Attached is what I want to draw. The lines I want to add are in blue (I'll want different colors, but drew them in blue, so you know what I'm trying to do).

Thanks!
premarket_lines.png

  Re: drawing horizontal lines that stop at start
Posted by dave on Jan-10-2023 21:55
Attachments:
btw, I know the X & Y data values. I tried plotting them using .addLine() (I think that was the method I used, but I tried so many things, they are getting blurry), but, it didn't work. (lines didn't show up).

So, I'm guessing there is a difference between data values and the underlying xy cords (makes sense).

I just don't know how to translate accordingly.
premarket_lines2.png

  Re: drawing horizontal lines that stop at start
Posted by dave on Jan-10-2023 22:55
I think I may have this resolved. I'm testing using .addLineLayer(...) and I'm really close.

I'll let you know if I still need help.

Thanks!

  Re: drawing horizontal lines that stop at start
Posted by Peter Kwan on Jan-11-2023 02:36
Hi Dave,

Sorry for the late reply.

The line you need can be drawn by using Axis.addMark and use an x-zone color as the line color. The following is an example using an x-zone color:

https://www.advsofteng.com/doc/cdnet.htm#xzonecolor.htm

Basically, an x-zone color is color that changes based whether the pixel is on the left or right side of a given x-data value. If you set an mark line with the red color on the left side, and transparent color on the right side, you can get a line that stops at the middle.

It is also possible to cascade x-zone color. For example, an x-zone color can be the red color on the left side, and on the right side, it is another x-zone color. In this way, you can create a line that is visible two values x1 and x2, like:

// Line color is 0x333399 beteween 10 and 20
int myLineColor = c.xZoneColor(10, Chart.Transparent, c.xZoneColor(20, 0x333399, Chart.Transparent)

Note that the x-coordinate for a FinanceChart is the trading session count 0, 1, 2, 3, 4, ...  The first visible candlestick is x=0, the second visible candlestick is x=1, etc.. (The x=0, 1, 2, ... refers to the center position of the candlestick.) You can use fractional x values if you want the line to stop at the gap between two candlesticks. For example, c.xZoneColor(-1, 0xff0000, 3.5) will start from the left side, and ends at the middle point between the 4th and 5th candlesticks.

Best Regards
Peter Kwan

  Re: drawing horizontal lines that stop at start
Posted by dave on Jan-11-2023 04:33
wow. Thanks!

  Re: drawing horizontal lines that stop at start
Posted by Peter Kwan on Jan-11-2023 14:13
Hi dave,

There is a mistake in the last paragraph of my previous post. The xZoneColor should be:

// red color starts from the left, and stops at the middle of the gap between the
// 4th and 5th candlesticks.
int myLineColor = c.xZoneColor(3.5, 0xff0000, Chart.Transparent);

Best Regards
Peter Kwan