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
TChartSeries.CalcFirstLastVisibleIndex not quite as expected
Re: TChartSeries.CalcFirstLastVisibleIndex not quite as expected
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:
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.
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;
Thanks in advance.
Best Regards,
Yeray Alonso Development & Support Steema Software Av. Montilivi 33, 17003 Girona, Catalonia (SP) | |
Please read our Bug Fixing Policy |
Re: TChartSeries.CalcFirstLastVisibleIndex not quite as expected
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
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 (35.44 KiB) Viewed 16409 times
-
- 3. Zoom Extents.gif (38.04 KiB) Viewed 16409 times
-
- TeeChartMain.zip
- (54.32 KiB) Downloaded 1214 times
Re: TChartSeries.CalcFirstLastVisibleIndex not quite as expected
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
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,
Yeray Alonso Development & Support Steema Software Av. Montilivi 33, 17003 Girona, Catalonia (SP) | |
Please read our Bug Fixing Policy |
Re: TChartSeries.CalcFirstLastVisibleIndex not quite as expected
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
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
Hello,
None that I am aware of. But if you find anything else we'll be pleased to take a look at it.
Best Regards,
Yeray Alonso Development & Support Steema Software Av. Montilivi 33, 17003 Girona, Catalonia (SP) | |
Please read our Bug Fixing Policy |