Page 1 of 1

TChart.Zoom event fired before some properties are updated

Posted: Tue Dec 16, 2014 8:59 am
by 16568648
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;

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

Posted: Tue Dec 16, 2014 9:25 am
by yeray
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.

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

Posted: Tue Dec 16, 2014 11:56 am
by 16568648
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

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

Posted: Tue Dec 16, 2014 3:08 pm
by yeray
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.