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

Message ListMessage List     Post MessagePost Message

  alignlayer not working inside loop
Posted by kay on Sep-11-2012 22:53
Attachments:
I have to align the line layer and Bar layer in a combination chart. The bars are not centered exactly on the x-position, but are shifted. On the other hand the individual data points on the line layer are centered exactly over the x-position.

The problem is how I can align the layer and Bar layer  using "alignlayer" as I am using loop to create the layers. Please provide the code fragment if possible. Here is my code:

if ChartType = "BARLINE" then

Call c.xAxis().setWidth(2)

     Call c.yAxis().setWidth(2)

        Set linelayer = c.addLineLayer()

Call linelayer.setLineWidth(2)

  for i = 1 to MaxData

          Call linelayer.addDataSet(data(i), DataColor(i)).setDataSymbol( cd.DiamondSymbol,8)

  next

Set barlayer = c.addBarLayer2(cd.Side)

Call barlayer.setBorderColor(-1,1)

for i = 1 to MaxData

if ubound(datax(i)) > 0  then

Call barlayer.addDataSet(datax(i), DataColor(i),Legend(i))

end if

next

Call barlayer.setBarGap(0.2, cd.TouchBar)

end if
Chart Image.png

  Re: alignlayer not working inside loop
Posted by Peter Kwan on Sep-12-2012 02:21
Hi kay,

You may use Layer.alignLayer. It is something like:

'Draw Bar Layer
Set barlayer = c.addBarLayer2(cd.Side)
Call barlayer.setBorderColor(-1,1)
for i = 1 to MaxData
    if ubound(datax(i)) > 0  then
        Call barlayer.addDataSet(datax(i), DataColor(i),Legend(i))
    end if
Next

'Draw Line Layers
for i = 1 to MaxData
    Set linelayer = c.addLineLayer2()
    Call linelayer.setLineWidth(2)
    Call linelayer.addDataSet(data(i), DataColor(i)).setDataSymbol( cd.DiamondSymbol,8)
    Call barlayer.alignLayer(layer, i)
    Call lineLayer.moveFront()
next

Hope this can help.

Regards
Peter Kwan

  Re: alignlayer not working inside loop
Posted by kay on Sep-12-2012 15:44
Attachments:
Hi Peter,

Thanks for the reply. The line "Call barlayer.alignLayer(layer, i)" was throwing an error so I changed it to "Call linelayer.alignLayer(barlayer, i-1)" and I got what I was trying to achieve.


However, if there is no BARLAYER for any X-axis point then still the LINELAYER points are dispersed. Is it possible to have selective alignment of LINELAYER point depending on if the BARLAYER points are present or not.

Thanks and Regards,
Kay
Chart Image2.png

  Re: alignlayer not working inside loop
Posted by Peter Kwan on Sep-13-2012 00:36
Hi Kay,

ChartDirector cannot automatically align a certain point based on whether the bar at the corresponding position is visible or not.

If you would like to have "selective alignment", instead of using align layer, you would need to tell ChartDirector the x-position of every point in a line. This is by passing an x-data array to the line layer using Layer.setXData. The x-data coordinates at the tick position is x = 0, 1, 2, 3, ... If you need to "shift" the point so as to align it with a bar, you would need to add or subtract an offset value. The exact offset depends on your bar gap and sub-bar-gap configuration. There is a formula published in the following thread:

http://www.chartdir.com/forum/download_thread.php?bn=chartdir_support&thread=1253019973#N1257929480

Regards
Peter Kwan