Page 1 of 1
TCandleSeries and Marks
Posted: Mon Jan 16, 2012 10:37 pm
by 16459409
Hello,
I'm using Marks to insert some textual info over a candle chart but I've two problems:
1 - the mark text sometime overlaps the candle (it appears to be associated with Open value...) so I'd like to move every marks to a constant distance from High value. I tried ArrowLength but it moves all the marks... I also tried MoveTo but I cannot control marks position when scrolling and changing scale.... any idea?
1 - sometime I need a two-line mark text but if I try to insert a line break of any kind (TeeLineSeparator, #10, #13, #10 #13, ...) I always get a little box starting the second line, using Marks.MultiLine:=True or False doesn't help...
Thanks a lot!
Best Regards.
Re: TCandleSeries and Marks
Posted: Tue Jan 17, 2012 4:27 pm
by yeray
Hi Huke,
Huke wrote:1 - the mark text sometime overlaps the candle (it appears to be associated with Open value...) so I'd like to move every marks to a constant distance from High value. I tried ArrowLength but it moves all the marks... I also tried MoveTo but I cannot control marks position when scrolling and changing scale.... any idea?
You can recalculate the Marks position each time the chart is scrolled, zoomed, etc simply calling the method where this calculation is made on all the required events.
Huke wrote:1 - sometime I need a two-line mark text but if I try to insert a line break of any kind (TeeLineSeparator, #10, #13, #10 #13, ...) I always get a little box starting the second line, using Marks.MultiLine:=True or False doesn't help...
This depends on the environment you are using. In VB6 you can use vbNewLine.
Find below an example where both features seem to work as expected in VB6 with the latest version v2011.0.0.5:
Code: Select all
Private Sub Form_Load()
TChart1.Aspect.View3D = False
TChart1.Legend.Visible = False
TChart1.Panel.MarginRight = 10
TChart1.AddSeries scCandle
TChart1.Series(0).FillSampleValues 10
Dim i As Integer
For i = 0 To TChart1.Series(0).Count - 1
TChart1.Series(0).PointLabel(i) = "Point nº" + Str$(i)
If i = 5 Then
TChart1.Series(0).PointLabel(i) = "Point" + vbNewLine + "nº" + Str$(i)
End If
Next i
TChart1.Series(0).Marks.Visible = True
TChart1.Series(0).Marks.Arrow.Color = vbBlack
MarksRepos
End Sub
Private Sub MarksRepos()
Dim i, vertOffset As Integer
Dim pos As ISeriesMarkPosition
Dim XVal, YVal As Double
TChart1.Environment.InternalRepaint
vertOffset = TChart1.Canvas.textHeight(" ") / 2
For i = 0 To TChart1.Series(0).Count - 1
XPos = TChart1.Series(0).XValues.Value(i)
YPos = TChart1.Series(0).asCandle.HighValues.Value(i)
With TChart1.Series(0).Marks.Positions.Position(i)
.Custom = True
.ArrowFrom.X = TChart1.Axis.Bottom.CalcXPosValue(XPos)
.ArrowFrom.Y = TChart1.Axis.Left.CalcYPosValue(YPos)
.LeftTop.X = .ArrowFrom.X + 5
.LeftTop.Y = .ArrowFrom.Y - vertOffset
.ArrowTo.X = .LeftTop.X
.ArrowTo.Y = .ArrowFrom.Y
End With
Next i
End Sub
Private Sub TChart1_OnResize()
MarksRepos
End Sub
Private Sub TChart1_OnScroll()
MarksRepos
End Sub
Private Sub TChart1_OnUndoZoom()
MarksRepos
End Sub
Private Sub TChart1_OnZoom()
MarksRepos
End Sub
- Chart1.png (9.87 KiB) Viewed 4407 times
Re: TCandleSeries and Marks
Posted: Mon Jan 30, 2012 10:07 pm
by 16459409
Hello Yeray, thanks for the kind reply.
Unfortunately using your example in my code it doesn't seems to work... when I scroll the chart the marks sometimes go to the ceiling of chart, sometime disappears.
I use Delphi XE and TeeChart Pro v2011.03.30407 Win32
This is the code I use:
Code: Select all
procedure TfrmChart.MarksSetPosition();
Var
i, vertOffset :Integer;
XPos, YPos :Double;
begin
vertOffset := Chart.Canvas.textHeight(' ') div 2;
For i := 0 To Chart.Series[0].Count - 1 do
Begin
XPos := Chart.Series[0].XValues.Value[i];
YPos := (Chart.Series[0] As TCandleSeries).HighValues.Value[i];
if (Chart.Series[0].Marks.Positions.Position[i]) <> nil then
Begin
With (Chart.Series[0].Marks.Positions.Position[i]) Do
Begin
Custom := True;
ArrowFrom.X := Chart.BottomAxis.CalcXPosValue(XPos);
ArrowFrom.Y := Chart.LeftAxis.CalcYPosValue(YPos);
LeftTop.X := ArrowFrom.X + 5;
LeftTop.Y := ArrowFrom.Y - vertOffset;
ArrowTo.X := LeftTop.X;
ArrowTo.Y := ArrowFrom.Y;
End;
End;
End;
End;
About multiline mark also I've some problems:
the method "PointLabel" you indicate it doesn't seems to exist.
I tried with:
Code: Select all
(Chart.Series[0] As TCandleSeries).Marks.Item[i].Text.Text := 'line1' + TeeLineSeparator + 'line2';
but I always get a little box shaped character starting the second line.
I believe it's something related to unicode but I cannot understand what...
Thank a lot!
Best Regards.
Huke
Re: TCandleSeries and Marks
Posted: Tue Jan 31, 2012 10:08 am
by yeray
Hi Huke,
Huke wrote:I use Delphi XE and TeeChart Pro v2011.03.30407 Win32
Oups. It seems I thought we were in the AX forum
Huke wrote:Unfortunately using your example in my code it doesn't seems to work... when I scroll the chart the marks sometimes go to the ceiling of chart, sometime disappears.
I see you translated the majority of the code from VB to Delphi without too much problems. However, I don't see the equivalent for the InternalRepaint call. Note, you need to be sure the chart has just been drawn so the CalcXPosValue & CalcYPosValue can work as expected. Anyway, maybe in your complete code you ensure it before calling the MarksSetPosition procedure.
I've tried your code (with some little adjustments) in a new simple application and it seems to work fine for me here, also with XE + TeeChart v2011.03.
Huke wrote:About multiline mark also I've some problems:
the method "PointLabel" you indicate it doesn't seems to exist.
I tried with:
Code: Select all
(Chart.Series[0] As TCandleSeries).Marks.Item[i].Text.Text := 'line1' + TeeLineSeparator + 'line2';
but I always get a little box shaped character starting the second line.
I believe it's something related to unicode but I cannot understand what...
I've used Chart1[0].Labels.Labels
and TeeLineSeparator in the example above and it seems to work fine. #13#10 also worked fine for me here.