Print Page | Close Window

Annotation - form fails to paint correctly

Printed From: TMS Software
Category: VCL Components
Forum Name: VCL Chart
Forum Discription:
URL: http://www.tmssoftware.com/site/forum/forum_posts.asp?TID=7964
Printed Date: 18 Oct 2019 at 5:49pm


Topic: Annotation - form fails to paint correctly
Posted By: Robson John
Subject: Annotation - form fails to paint correctly
Date 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.



Replies:
Posted By: Pieter Scheldeman
Date 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.


Posted By: Robson John
Date 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.


Posted By: Robson John
Date Posted: 29 Jun 2017 at 12:58pm
Thanks again Pieter,

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

John.



Print Page | Close Window