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

Message ListMessage List     Post MessagePost Message

  Adding objects to Scatter Layer (incrementally) after Layer has been created...
Posted by Chuck on Nov-23-2020 05:11
Hi Peter,

I’m reviewing the VB.NET code shown here...
https://www.advsofteng.com/doc/cdnet.htm#scattertrend.htm

I want to create a ScatterLayer *prior* to knowing the objects that are to be added... can you provide an example of adding objects to the Scatter Layer after it is created? I want all objects added to the single Scatter Layer (incrementally) such that I can tie the single Layer to a Show/Hide button that will toggle the Layer (Show) on and off.

Thank you.
Chuck

  Re: Adding objects to Scatter Layer (incrementally) after Layer has been created...
Posted by Peter Kwan on Nov-23-2020 23:58
Hi Chuck,

This is similar to a Realtime Chart. The layers are drawn, and new data points are subsequently added. In the Realtime Chart sample code, the new data points are added by a timer. For your case, they are added by your code trigger by timer or some other user actions.

In brief, the code structure is like:

Dim xData As New List(Of Double)
Dim yData As New List(Of Double)


Sub DrawChart()

.... create chart as usual ....

c.addScatterLayer(xData.ToArray(), yData.ToArray(), .....)

....

winChartViewer1.Chart = c

End Sub


You can add, delete or change the data in your scatter layer by modifying the xData and yData, and then call DrawChart.


Hope this can help.

Regards
Peter Kwan

  Re: Adding objects to Scatter Layer (incrementally) after Layer has been created...
Posted by Chuck on Nov-24-2020 00:22
Thank you Peter, you are very helpful as always!
Best,
Chuck

  Re: Adding objects to Scatter Layer (incrementally) after Layer has been created...
Posted by Chuck on Nov-24-2020 02:45
Follow-up...

.addScatterLayer wants to see a Double data type for both X and Y Lists (arrays). My Chart uses a Date data type for the X Axis... what am I missing for the new Scatter Layer to use Date as the X Axis component?

What I thought was straight-forward has revealed a huge gap in my knowledge about what you previously posted.

Ideally, I want to incrementally place objects (polygons) on the Scatter Layer at the intersection of X (Date) and Y (Price). Had no problem with this with the OHLCV Charts.

Thank you for your help.
Chuck

  Re: Adding objects to Scatter Layer (incrementally) after Layer has been created...
Posted by Peter Kwan on Nov-24-2020 12:10
Hi Chuck,

In ChartDirector, if an API requires Double(), but you want to use DateTime() (or Date() in VB), you can use Chart.CTime to convert the Date() to Double(). It is like:

c.addScatterLayer(Chart.CTime(myArrayOfDates), yData, ....)

Are you trying to add symbols to a FinanceChart object? For FinanceChart, the x-coordinates are not date/time. You can just pass Nothing for the x-coordinates, like:

c.addScatterLayer(Nothing, yData, ....)

For the yData array, it is the similar to the high/low/open/close/vol arrays. You can put a value to the slot you want to have a scatter symbol. If a slot has no symbol, you can put in Chart.NoValue. For your case, you can declare an array the same size as your closeData array, and fill it with Chart.NoValue. You can then put values in it to update the array.

(Financial charts use "trading sessions" as the x-coordinates, not date/time. It is because the dates/times are somewhat "random and unpredictable" and does not reflect the spacing between the data points. They are random because the trading days can be affected by natural phenomena such as hurricanes and typhoons or other unpredictable factors. The date/time are just treated as names for human reading, and the data points are always plotted as evenly spaced horizontally regardless of the date/time.)

Regards
Peter Kwan

  Re: Adding objects to Scatter Layer (incrementally) after Layer has been created...
Posted by Chuck on Nov-24-2020 12:58
This is helpful Peter, thank you.

Yes, over the OHLCV Financial Chart, I need to be able to place any number of polygon/symbols on a single bar - at different price points.

So, assuming I would be converting the date of the bar to a double, and place it in the XData array... with the Price As Double in the YData array...? (For the Scatter Layer)

Chuck

  Re: Adding objects to Scatter Layer (incrementally) after Layer has been created...
Posted by Peter Kwan on Nov-24-2020 16:42
Hi Chuck,

If you want to put the scatter symbols anywhere (even in between two candlesticks, or multiple symbols on the same x position) on the chart, you can use both the x and y coordinates. The x-coordinate in this case is the trading session number 0, 1, 2, 3, 4, .... The array index 0 refers to the first visible bar on the chart, 1 is the second visible bar on the chart.

Another complication is that the FinanceChart will not plot the first N data points, where N is specified as the extraPoints parameter in FinanceChart.setData. See:

https://www.advsofteng.com/doc/cdnet.htm#FinanceChart.setData.htm


So for your case, the code would be like:

Dim xData As New List(Of Double)
Dim yData As New List(Of Double)


Sub DrawChart()

.....


'
' Insert some dummy values for the FinanceChart to discard
'
Dim xScatterLayer() As Double = New ArrayMath(xData.ToArray()).insert(Chart.NoValue, extraPoints, 0).result()

Dim yScatterLayer() As Double = New ArrayMath(yData.ToArray()).insert(Chart.NoValue, extraPoints, 0).result()

c.addScatterLayer(xScatterLayer, yScatterLayer, ....)

....

End Sub


For the x-coordinates, note that the coordinate 0 refers to the first visible bar on the chart. The first visible bar is the one with timeStamp[extraPoints], because timeStamps[0] to timeStamps[extraPoints - 1] are not visible.

Regards
Peter Kwan

  Re: Adding objects to Scatter Layer (incrementally) after Layer has been created...
Posted by Chuck on Nov-24-2020 20:11

Thank you Peter.

  Re: Adding objects to Scatter Layer (incrementally) after Layer has been created...
Posted by Chuck on Nov-24-2020 22:24

Thank you Peter.

  Re: Adding objects to Scatter Layer (incrementally) after Layer has been created...
Posted by Chuck on Nov-25-2020 00:17

Peter,

So, regarding multiple symbols on the same Financial Chart Bar... how is this done using a single Scatter Layer?

At the end, I prefer 1 Scatter Layer so I can Show/Hide it...

Let’s say the DateTime of the Financial Bar is index 20... YData(20) can only hold 1 Price/double value... my signal data is real-time, I never know how many symbols/signals will be occurring on each bar...

How would this be accomplished?

Thank you,
Chuck

  Re: Adding objects to Scatter Layer (incrementally) after Layer has been created...
Posted by Peter Kwan on Nov-25-2020 10:58
Hi Chuck,

The code in my last message contains only 1 scatter layer, and you can put multiple symbols on each bar. For example:

'One symbol at bar index 20, at price = 111
xData.Add(20)
yData.Add(111)

'Another symbol at bar index 20, at price = 124
xData.Add(20)
yData.Add(124)

'Another symbol at bar index 30, at price = 99
xData.Add(30)
yData.Add(99)

'Update the chart to reflect the symbols
DrawChart()

Later, if you have more symbols, you can add more them to xData and yData and call DrawChart again.

The DrawChart only creates one scatter layer, so there is one scatter layer for all the symbols.

Hope this can help.

Regards
Peter Kwan

  Re: Adding objects to Scatter Layer (incrementally) after Layer has been created...
Posted by Chuck on Nov-25-2020 21:16

Thank you Peter, great detail. I understand now. Perfect.
Best,
Chuck

  Re: Adding objects to Scatter Layer (incrementally) after Layer has been created...
Posted by Chuck on Nov-25-2020 21:34

Peter, one last detail... how is DrawChart() called? I can’t find that method...

Thank you,
Chuck

  Re: Adding objects to Scatter Layer (incrementally) after Layer has been created...
Posted by Peter Kwan on Nov-25-2020 23:06
Hi Chuck,

DrawChart is the subroutine that you write to draw the chart. In other words, you can put your charting code in that subroutine, and call it when you want to draw or update the chart.

In some our sample code, we call it "createChart". In other, we call it "drawChart". See:

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

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

The createChart/drawChart is just a name. In your real code, you can use any name you like for your subroutine. I just use DrawChart in my previous message.

Regards
Peter Kwan

  Re: Adding objects to Scatter Layer (incrementally) after Layer has been created...
Posted by Chuck on Nov-25-2020 23:31

Thank you.
Chuck