Web forum is in read-only mode. Login as active registered customer for write access
  Forum Search   New Posts New Posts

Annotation - form fails to paint correctly

 Post Reply Post Reply
Author
Robson John View Drop Down
New Member
New Member
Avatar

Joined: 25 Feb 2017
Posts: 3
Post Options Post Options   Quote Robson John Quote  Post ReplyReply Direct Link To This Post Topic: Annotation - form fails to paint correctly
    Posted: 29 Jun 2017 at 12:58pm
Thanks again Pieter,

Problem fixed. I added that code to OnFormShow. Everything works well now.

John.
Back to Top
Robson John View Drop Down
New Member
New Member
Avatar

Joined: 25 Feb 2017
Posts: 3
Post Options Post Options   Quote Robson John Quote  Post ReplyReply Direct Link To This Post Posted: 29 Jun 2017 at 12:50pm
Thank you Pieter. I will check that now.

Also, I just figured out Delphi has a DayOfTheYear function for my second issue.

John.
Back to Top
Pieter Scheldeman View Drop Down
TMS Support
TMS Support
Avatar

Joined: 18 May 2010
Posts: 3329
Post Options Post Options   Quote Pieter Scheldeman Quote  Post ReplyReply Direct Link To This Post Posted: 29 Jun 2017 at 12:37pm
Hi, 

You should avoid adding code that adds an annotation or any other item to a collection in a draw event. The OnAfterDrawSeries is called multiple times as this event is called after a series is drawn. You can simply move the code in the constructor of the form and only call it once after setting the dataset to active programmatically, which should be sufficient to show an annotation. The chart itself is responsible for drawing it.


Edited by Pieter Scheldeman - 29 Jun 2017 at 12:38pm
Back to Top
Robson John View Drop Down
New Member
New Member
Avatar

Joined: 25 Feb 2017
Posts: 3
Post Options Post Options   Quote Robson John Quote  Post ReplyReply Direct Link To This Post Posted: 29 Jun 2017 at 12:34pm
Hello all,

May I ask for some help please.

I have a DBAdvGDIPChartView that displays a product price over a period of time. The x-axis of the chart is a date. I would like to add an annotation to mark todays date, however, I am having 2 problems.

Problem 1. This is the code I use to add the annotation. This works great if I call it from a button on the form, but I would rather that chart just added the annotation after it loaded the series.

uses
  AdvChartView, AdvChartViewGDIP, DBAdvChartViewGDIP, AdvChart


  DBAdvGDIPChartView1.BeginUpdate;
  with DBAdvGDIPChartView1.Panes[0].Series[0].Annotations.Add do
  begin
    Text := 'Today';
    PointIndex := 10;
    OffsetY := -50;
    OffsetX := 10;
    Color :=  clred;
    //ColorTo := Lighter(Color, 40);
    //GradientType := gtForwardDiagonal;
    Bordercolor := clBlack;
    OpacityTo := 180;
    OpacityTo := 180;
    Shape := TAnnotationShape(4);
    LineColor := clred;//Color;
    Arrow := arDoubleArrow;
    ArrowColor := Color;
  end;
  DBAdvGDIPChartView1.EndUpdate;

If I add the above code to the 'OnAfterDrawSeries' event the form that the chart resides on fails to paint correctly. When using the OnAfterDrawSeries event (and many others too) the event is called multiple times and perhaps this has something to do with the painting of the form.

May I ask, which events can I use to draw a single annotation correctly?

Problem 2. My x-axis is a date (the date is pulled from a query). May I ask how I find the appropriate 'PointIndex' for a date on x-axis that represents today?

Thank you for your time.
John.
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down