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

Message ListMessage List     Post MessagePost Message

  ScatterLayer is under HLOClayer
Posted by Steve on Dec-09-2010 05:15
Hi Peter,

I am trying to add annotations to a financial chart using the ScatterLayer.  However, the annotations are being covered by the price bars.  I tried setting the Zorder, but it didn't work.

ScatterLayer buylayer = mc.addScatterLayer(null, indicators, "", 0, 0, Chart.Transparent, 0x000000);
buylayer.addExtraField(labels);
buylayer.setDataLabelFormat("{field0}");
ChartDirector.TextBox buytextbox = buylayer.setDataLabelStyle("Arial", 7);

buytextbox.setBackground(0xFFFFFF, 0xFFFFFF, 1);
buytextbox.setAlignment(Chart.Right);
buytextbox.setPos(0, 15);
//buytextbox.setZOrder(??);

Thanks for your help

  Re: ScatterLayer is under HLOClayer
Posted by Peter Kwan on Dec-09-2010 15:48
Hi Steve,

For your case, you would need to move the layer in front of the other layers by using Layer.moveFront. For example:

buylayer.moveFront();

Hope this can help.

Regards
Peter Kwan

  Re: ScatterLayer is under HLOClayer
Posted by Steve on Dec-17-2010 05:33
Thanks Peter, that did it.

The scatterlayer is good.. is it possible to add an arrow (pointing to the right) to the tick?

I moved the textbox to the left of the point:

                buytextbox.setAlignment(Chart.Right);
                buytextbox.setPos(-8, 0);


Thank you again for the help

  Re: ScatterLayer is under HLOClayer
Posted by Peter Kwan on Dec-17-2010 23:02
Hi Steve,

I am not exactly sure where would you like to add the arrow. In paritcular, I am not sure where is the "tick"?

In ChartDirector terminology, we called the small marks on the axis the ticks. There are ticks on the various vertical and horizontal axes, and the arrow can be put at various position of the tick.

However, I am suspect may be you are not referring to the above kind of ticks. Are you referring to the "annotations" that you are adding to the chart?

In general, there are several common methods to add arrows to a chart:

(a) Add them as part of a label, using a triangle character. Many fonts have characters that are arrows or triangle shapes (eg. the characters \\u2192 and \\u25BA in Arial). By controlling the chracter size, color, and position using CDML (see CDML in the ChartDirector documentation index), one can often get the desired result.

(b) Add a scatter layer, using or a triangle an arrow as the symbol.

(c) Add a vector layer.

(d) Draw them using the DrawArea object (DrawArea.polygon)

If you need further help, please kindly clarify where would you like to arrow to appear.

Hope this can help.

Regards
Peter Kwan

  Re: ScatterLayer is under HLOClayer
Posted by Steve on Dec-18-2010 00:07
Attachments:
Peter,

Here is the code that I have to draw the annotation:

ScatterLayer buylayer = mc.addScatterLayer(null, indicators, "", 0, 0, 0x000000, 0x000000);
buylayer.addExtraField(labels);
buylayer.setDataLabelFormat("{field0}");
buylayer.moveFront();

ChartDirector.TextBox buytextbox = buylayer.setDataLabelStyle("Arial", 7);
buytextbox.setBackground(0xFFFFFF, 0xFFFFFF, 1);
buytextbox.setAlignment(Chart.Right);
buytextbox.setPos(-8, 0);

I want to add a small arrow to the right of the textbox which points to the price it is associated to.

Thanks.
annotation.png

  Re: ScatterLayer is under HLOClayer
Posted by Steve on Dec-18-2010 07:16
Peter,

so I decided to use the vectorlayer to add the arrows.

VectorLayer arrows = mc.addVectorLayer(null, indicators, radii, angels, ChartDirector.Chart.YAxisScale, 0x808285);

arrows.setArrowHead(7);

the arrow is showing now..  however, it is making my yaxis begin at 0..  i initialized my radii, angels array to Chart.NoValue.

do you have any suggestions?

Thanks

  Re: ScatterLayer is under HLOClayer
Posted by Peter Kwan on Dec-18-2010 17:23
Hi Steve,

If I were you, I will probably add the arrow in the scatter layer. For example, you may use a right pointing triangle as the scatter symbol, with the right vertice at the data point. The code is like:

//The symbol shape is designed so that the left half of the shape is a rightwards pointing triangle,
//while the right half is empty.
buylayer.getDataSet(0).setDataSymbol4(new int[] {-500, 750, 0, 500, -500, 250}, 14,  0x808285);

The vector layer is most useful if you would like to make arrows that point in arbitrarily directions with arbitrary lengths (eg. arrows that joins two arbitrary data points). For your current case, as the arrow is of constant shape and size, it can be considered as a symbol and it is easier to use a scatter layer.

If you would like to use the vector layer, but the y-axis starts from 0, may be you can try:

//Ask ChartDirector not to favour using 0 as the axis starting point
mc.yAxis().setAutoScale(0.1, 0.1, 0);

Hope this can help.

Regards
Peter Kwan

  Re: ScatterLayer is under HLOClayer
Posted by Steve on Dec-21-2010 00:24
Attachments:
Hi Peter,

I am going to use the vector layer since one of the requirements is to have variable length arrows.

I am setting the yAxis to a linearscale which makes the chart look the way we want it.

VectorLayer arrows = mc.addVectorLayer(null, indicators, radii, angels, ChartDirector.Chart.YAxisScale, 0x808285);
arrows.setArrowHead(4);
mc.yAxis().setAutoScale(0.1, 0.1, 0);

Adding the vectorlayer and setting the autoscale still starts the axis at 0.

Do you have any suggestions as to how to keep the scaling the same?

Thanks so much,
Steve
linear.png
auto.png

  Re: ScatterLayer is under HLOClayer
Posted by Peter Kwan on Dec-21-2010 03:57
Hi Steve,

May be you can try to call BaseChart.layoutAxes before adding the vector layer. In this case, the axis scale will be determined only by the layers added before BaseChart.layoutAxes is called. The vector layer therefore cannot affect the axis scale.

The code structure should be like:

... add all layers except the vector layer ....

mc.layoutAxes();

... add vector layer ...

Hope this can help.

Regards
Peter Kwan

  Re: ScatterLayer is under HLOClayer
Posted by Steve on Dec-21-2010 04:49
Thanks Peter!  that worked