TChart.Zoom event fired before some properties are updated

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
ChristianH
Newbie
Newbie
Posts: 5
Joined: Tue Mar 04, 2014 12:00 am

TChart.Zoom event fired before some properties are updated

Post by ChristianH » Tue Dec 16, 2014 8:59 am

TLineSeries: After a Zoom I want to react to the now displayed data range. I.e. I need to know then Series.FirstValueIndex/Series.LastValueIndex. But at least these two properties are within the TChart.Zoom event not yet set. a) Should this be considered as a bug? b) I mad a workaround by inserting Chart.Repaint within that event, which causes the properties to be updated. Is this ok, or is there another cleaner solution?

This is the code fragment showing the behaviour (the whole sample project is also attached):

Code: Select all

procedure TForm6.Chart1Zoom(Sender: TObject);
begin
  Chart1.Repaint;      // Needed in order to have e.g. "Series1.FirstValueIndex", "Series1.LastValueIndex" updated
  ShowValueIndexBounds;
end;

procedure TForm6.ShowValueIndexBounds;
begin
  Self.Caption := Format('%d, %d', [Series1.FirstValueIndex, Series1.LastValueIndex]);
end;
Attachments
Projects.zip
Sample project
(1.94 KiB) Downloaded 385 times

Yeray
Site Admin
Site Admin
Posts: 9533
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: TChart.Zoom event fired before some properties are updated

Post by Yeray » Tue Dec 16, 2014 9:25 am

Hello,

This is normal. This event is fired when the chart hasn't been completely redrawn yet so some internal properties haven't been set yet.
Forcing a chart repaint as you did is an option.
Another option could be to set a flag at OnZoom and check that flag at OnAfterDraw (and reset the flag there too to avoid endless loops), where the needed internal properties will probably have been set.
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

ChristianH
Newbie
Newbie
Posts: 5
Joined: Tue Mar 04, 2014 12:00 am

Re: TChart.Zoom event fired before some properties are updated

Post by ChristianH » Tue Dec 16, 2014 11:56 am

Hi Yeray,
ok, I understand that I have to manually repaint the chart.
But with respect, in what circumstance makes that event sense if the new values cannot be accessed (by default). I thought that with that OnZoom I could update the user interface with actual values. As mentioned the Manual repaint does that but IMO it should already be done in the internal OnZoom handler.
Best,
Christian

Yeray
Site Admin
Site Admin
Posts: 9533
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: TChart.Zoom event fired before some properties are updated

Post by Yeray » Tue Dec 16, 2014 3:08 pm

Hello Christian,

If you look at the sources, you'll see how, when MouseUp is fired in TCustomChart, we check if a zoom has to be done, the axes are rescaled accordingly and a chart repaint is forced.
Since OnAfterDraw event is already provided and can be handled to catch when a chart repaint has finished, I see correct OnZoom event being fired after the axes rescale and before the chart repaint.
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Post Reply