Page 1 of 1

TChartSeries.CalcFirstLastVisibleIndex not quite as expected

Posted: Mon Oct 26, 2015 11:33 am
by 16575285

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?



Re: TChartSeries.CalcFirstLastVisibleIndex not quite as expected

Posted: Fri Oct 30, 2015 10:58 am
by yeray
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;




  Caption:='FirstValueIndex: ' + IntToStr(x0) + ', LastValueIndex: ' + IntToStr(x1);
  Chart1.Axes.Bottom.SetMinMax(Series1.XValue[x0], Series1.XValue[x1]);
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.

Re: TChartSeries.CalcFirstLastVisibleIndex not quite as expected

Posted: Thu Sep 24, 2020 11:06 am
by 16589505

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?



Re: TChartSeries.CalcFirstLastVisibleIndex not quite as expected

Posted: Wed Sep 30, 2020 9:33 am
by yeray
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';
  Self.stbPoints.SimpleText := Format(strFORMAT, [Self.chsFastLine.VisibleCount,
    Self.chsFastLine.FirstDisplayedIndex, Self.chsFastLine.LastDisplayedIndex,
    Self.chsFastLine.FirstValueIndex, Self.chsFastLine.LastValueIndex]);