TChartSeries.CalcFirstLastVisibleIndex not quite as expected

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
Toreba
Newbie
Newbie
Posts: 29
Joined: Wed Sep 02, 2015 12:00 am

TChartSeries.CalcFirstLastVisibleIndex not quite as expected

Post by Toreba » Mon Oct 26, 2015 11:33 am

Hi,

I am using TeeChart Pro 2013.09.131119 32-bit VCL in Delphi XE5.

I have a series of three points plotted against a date-time x-axis. I set the x-axis extents such that the axis minimum has the same x-value as the first point, and the axis maximum has the same x-value as the last point. I run TChart.Refresh, then TChartSeries.CalcFirstLastVisibleIndex.

I then find that TChartSeries.FirstValueIndex = 0 and TChartSeries.LastValueIndex = 0.

And yet two points are visible (and three should be).

What am I doing wrong?

Regards

Toreba

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

Re: TChartSeries.CalcFirstLastVisibleIndex not quite as expected

Post by Yeray » Fri Oct 30, 2015 10:58 am

Hello Toreba,

I've given a try to the code below with the latest version and it seems to work fine for me after forcing a chart repaint with Chart1.Draw:

Code: Select all

uses Series;

procedure TForm1.FormCreate(Sender: TObject);
var Series1: TChartSeries;
    x0, x1: Integer;
begin
  Chart1.View3D:=false;

  Series1:=Chart1.AddSeries(TPointSeries);
  Series1.XValues.DateTime:=true;
  Series1.FillSampleValues(3);

  Chart1.Draw;

  x0:=Series1.FirstValueIndex;
  x1:=Series1.LastValueIndex;

  Caption:='FirstValueIndex: ' + IntToStr(x0) + ', LastValueIndex: ' + IntToStr(x1);
  Chart1.Axes.Bottom.SetMinMax(Series1.XValue[x0], Series1.XValue[x1]);
end;
If you still find problems with it, could you please arrange a simple example project we can run as-is to reproduce the problem here?
Thanks in advance.
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

toreba
Newbie
Newbie
Posts: 1
Joined: Fri Sep 18, 2020 12:00 am

Re: TChartSeries.CalcFirstLastVisibleIndex not quite as expected

Post by toreba » Thu Sep 24, 2020 11:06 am

Hi,

Returning to this post from five years ago, I never had time to pursue the problem, but I need to now. The issue seems to persist today with TeeChart Pro v2019.27.190530 32bit VCL in Delphi 10.3 Version 26.0.33219.4899. Not sure that it has been dealt with in any other posts on this forum. The attached project shows what happens.

I fill an inverted, stair-mode TFastLineSeries on a date-time horizontal axis with 1000 random points. The series is displayed.

I call CalcFirstLastVisibleIndex. The series' VisibleCount property is then zero, as are its FirstDisplayedIndex, LastDisplayedIndex, FirstValueIndex and LastValueIndex. That's wrong for a start.

I zoom in using the mouse, call CalcFirstLastVisibleIndex in the OnZoom event. Then the series reports 1000 displayed points, first and last indices 0 and 999. So, wrong again, one step behind.

I zoom out using the mouse, call CalcFirstLastVisibleIndex in the OnUndoZoom event. The series now reports 529 displayed points, between indices 80 and 608. Again, wrong and one step behind.

Calling CalcFirstLastVisibleIndex twice doesn't help.

So, clearly I misunderstand the meaning of this method and these properties. How do I get the series to tell me how many points it has displayed?

And what is the difference between FirstDisplayedIndex and FirstValueIndex? When are they ever different?

Regards

Toreba
Attachments
2. Zoom In.gif
2. Zoom In.gif (35.44 KiB) Viewed 1005 times
3. Zoom Extents.gif
3. Zoom Extents.gif (38.04 KiB) Viewed 1005 times
TeeChartMain.zip
(54.32 KiB) Downloaded 72 times

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

Re: TChartSeries.CalcFirstLastVisibleIndex not quite as expected

Post by Yeray » Wed Sep 30, 2020 9:33 am

Hello Toreba,

The issue is that you are calculating the first and last visible values in the series when the axis hasn't been yet recalculated. That's why this can be solved forcing a chart repaint Self.chtFastLine.Draw; or simply a bottom axis recalculation Self.chtFastLine.Axes.Bottom.AdjustMaxMin;:

Code: Select all

procedure TfrmFastLine.UpdateStatusBar;
const strFORMAT = 'Displayed points: %d; '
  + 'first displayed index: %d; last displayed index: %d; '
  + 'first value index: %d; last value index %d';
begin
  Self.chtFastLine.Axes.Bottom.AdjustMaxMin;
  Self.chsFastLine.CalcFirstLastVisibleIndex;
  Self.stbPoints.SimpleText := Format(strFORMAT, [Self.chsFastLine.VisibleCount,
    Self.chsFastLine.FirstDisplayedIndex, Self.chsFastLine.LastDisplayedIndex,
    Self.chsFastLine.FirstValueIndex, Self.chsFastLine.LastValueIndex]);
end;
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