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

Message ListMessage List     Post MessagePost Message

  Add border around a zone, best idea
Posted by icm63 on Apr-06-2020 03:16
Attachments:
Please see attached image for my request
ZoneBorder.png

  Re: Add border around a zone, best idea
Posted by Peter Kwan on Apr-06-2020 19:25
Hi icm63,

You can consider to draw 4 mark lines (Axis.addMark) to create the rectangle. This should work well if the line is thin. If the line is think (eg. 10 pixels thick line like in your image), it is better to draw it with a real rectangle using DrawArea.rect with the thick border achieved using the Chart.flatBorder.

https://www.advsofteng.com/doc/cdcppdoc/DrawArea.rect.htm
https://www.advsofteng.com/doc/cdcppdoc/Chart.flatBorder.htm

(A rectangle is not the same as 4 lines. The difference is in how the lines are joined at the corners. If the line width is 1, they look the same. If the line width is wide, it is difficult to draw the 4 lines so that they join property at the corners. So a real rectangle is recommended.)

Regards
Peter Kwan

  Re: Add border around a zone, best idea
Posted by icm63 on Apr-07-2020 10:55
Attachments:

I use this code to draw rectangle, note I run this code after layout() is called.

vb.net,asp.net, Chartdirector v6.0


'This draw ok
                TempXYChart.xAxis().addZone(ZoneStartBarNum - ExtraBars, FinalZoneEndBarNum - ExtraBars, ZoneColorAdj)



'This does not draw ???
                        DrawObjects_Rectangle(TempXYChart, CDbl(ZoneStartBarNum - ExtraBars), PriceLower, CDbl(FinalZoneEndBarNum - ExtraBars), PriceUpper)




    Private Sub DrawObjects_Rectangle(ByVal myChart As XYChart, ByVal BarNumberStart As Double, ByVal PriceStart As Double, _
    ByVal BarNumberEnd As Double, ByVal PriceEnd As Double)

        Dim x1 As Integer = myChart.getXCoor(BarNumberStart)
        Dim x2 As Integer = myChart.getXCoor(BarNumberEnd)
        Dim y1 As Integer = myChart.getYCoor(PriceStart)
        Dim y2 As Integer = myChart.getYCoor(PriceEnd)

'**********
'Puts variables to a text file
        Util.zPFile(BarNumberStart.ToString & " / " & PriceStart.ToString & " / " & BarNumberEnd.ToString & " / " & PriceEnd.ToString)


'Out put is OK, see here

BarNumberStart:1470 / PriceStart:230 / BarNumberEnd:755 / PriceEnd:300


'*********

        myChart.getDrawArea.rect(x1, y1, x2, y2, &H0, Chart.Transparent, Chart.flatBorder(-3))

    End Sub


On this chart below rectangle does not draw.

Note the pink shade square is from the 'addzone' code above.

Any ideas why my rectangle does not draw, the inputs are the same for the addZone function as I use for the rectangle.
SH_0009.png

  Re: Add border around a zone, best idea
Posted by Peter Kwan on Apr-07-2020 15:56
Hi icm63,

When you add objects to the chart (like addZone, addLineLayer, etc), those objects are not drawn yet. They are drawn when you call makeChart.

On the other hand, the DrawArea methods draw immediately. So in your code, DrawArea.rect will be drawn first, followed by the chart objects. Is it possible the DrawArea.rect is hidden by the pink zone or by the plot area background (in case the background is non-transparent)?

You can try to use:

myChart.makeChart().rect(x1, y1, x2, y2, &H0, Chart.Transparent, Chart.flatBorder(-3))

As makeChart is used, the chart is drawn, followed by the rectangle. The rectangle will then be on top of the chart. In the previous post, the green rectangle seems to be on top of the OHLC bars too, while the pink rectangle is under the OHLC bars.

Because makeChart is used, you should draw the green rectangle only if you have already add all the necessary objects to the chart.

As an alternative, you can use BaseChart.addText to add an empty text box, and configure it to have a thick border. The TextBox will be on top of the chart by default (configurable using Box.setZOrder).

Regards
Peter Kwan

  Re: Add border around a zone, best idea
Posted by icm63 on Apr-08-2020 02:14
This worked fine


myChart.makeChart().rect(x1, y1, x2, y2, &H0, Chart.Transparent, Chart.flatBorder(-3))