Page 1 of 1
TChartSeries.CalcFirstLastVisibleIndex not quite as expected
Posted: Mon Oct 26, 2015 11:33 am
by 16575285
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
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;
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.
Re: TChartSeries.CalcFirstLastVisibleIndex not quite as expected
Posted: Thu Sep 24, 2020 11:06 am
by 16589505
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
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';
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;
Re: TChartSeries.CalcFirstLastVisibleIndex not quite as expected
Posted: Wed Dec 09, 2020 11:44 am
by 16589505
Yeray,
Thank you for your reply from three months ago. I've been working on something else and only recently noticed this, so apologies for not following up sooner. The solution you advised works in my test application, but I've been struggling for hours and hours to understand why it didn't work in my main developments. I have been comparing chart and series properties, property by property, trying to find a difference.
Eventually I found the problem. I had XValues.Order:= loNone. If I change this to loAscending, then suddenly everything works as expected and life is wonderful again. I was using loNone, because when plotting 8 million points, I didn't want TeeChart to sort values when I was adding them in sorted order. Does loAscending impose any additional computational burden when adding points?
Regards
Toreba
Re: TChartSeries.CalcFirstLastVisibleIndex not quite as expected
Posted: Wed Dec 16, 2020 12:07 pm
by yeray
Hello,
toreba wrote: ↑Wed Dec 09, 2020 11:44 am
Does loAscending impose any additional computational burden when adding points?
None that I am aware of. But if you find anything else we'll be pleased to take a look at it.