Recent

Author Topic: [SOLVED] Increase TAChart drawing performence  (Read 819 times)

mig-31

  • Sr. Member
  • ****
  • Posts: 260
[SOLVED] Increase TAChart drawing performence
« on: September 11, 2019, 03:46:41 pm »
Hi,

I made a measurement program, which used TAChart to visualize measured values on the Chart. There is 16 TLineSeries with around 6000- 7000 points on each chart. Each chart have its own PageTab. Point show is disabled, according to TAChart documentation to speed up drawing, for example after zooming.

I added screenshots of two Charts. On the Chart1 there is no problem with redrawing. On the Chart2 after zooming it takes a few seconds to show a zoomed area. As I see the difference is on the Chart2 lines is crossed it each other in many points, instead of Chart1.
When I changed LineDemo examples to increase the number of crossing points it behaves the same like in my program.

Is there any way to speed up TAChart drawing or I shoud implement a Chart zooming with TChartNavScroolBars in run-time?

CentOS 7 Linux 64-bit.
FPC 3.0.4
Lazarus 3.0.2
Intel(R) Core(TM) i5-3570 CPU @ 3.40GHz

Thank you for any suggestion





« Last Edit: September 18, 2019, 02:15:02 pm by mig-31 »
Lazarus 2.0.2 - CentOS 7.x, Mageia 7.1

wp

  • Hero Member
  • *****
  • Posts: 6362
Re: Increase TAChart drawing performence
« Reply #1 on: September 11, 2019, 04:51:18 pm »
As I see the difference is on the Chart2 lines is crossed it each other in many points, instead of Chart1.
I cannot imagine how a crossover of series at many point should cause a slow-down.

Could you post the linedemo that you modified such that I can see the issue immediately without having to guess what you were doing exactly?

« Last Edit: September 11, 2019, 05:49:58 pm by wp »
Lazarus trunk / fpc 3.0.4 / all 32-bit on Win-10

mig-31

  • Sr. Member
  • ****
  • Posts: 260
Re: Increase TAChart drawing performence
« Reply #2 on: September 11, 2019, 05:56:14 pm »
Here is it.

Code: Pascal  [Select]
  1. procedure TForm1.btnAddSeriesClick(Sender: TObject);
  2. const
  3.   POINTS_PER_SERIE = 50000;
  4. var
  5.   s: TLineSeries;
  6.   i, j: Integer;
  7. begin
  8.   for i := 1 to 18 do begin
  9.     s := TLineSeries.Create(chFast);
  10.     s.SeriesColor := clRed;
  11.  
  12.     for j := 1 to POINTS_PER_SERIE do
  13.       //changed 10 to 0.1
  14.       s.AddXY(j, Random * 5 + chFast.SeriesCount * 0.1);
  15.     chFast.AddSeries(s);
  16.   end;
  17.   lblPointsCount.Caption :=
  18.     Format('Points: %.2e', [chFast.SeriesCount * POINTS_PER_SERIE * 1.0]);
  19. end;  
  20.  
Lazarus 2.0.2 - CentOS 7.x, Mageia 7.1

wp

  • Hero Member
  • *****
  • Posts: 6362
Re: Increase TAChart drawing performence
« Reply #3 on: September 11, 2019, 06:28:55 pm »
I suppose you refer to the page "Fast drawing" and press the "Add" button to add 50,000 data points. Then you zoom (this is per Shift-Left-Drag here, not the usual Left-Drag!). For me (Win 10, Laz 2.0.2, FPC 3.0.4) there is immediate reaction, no delay.

Please note that the ZoomDragTool becomes active in the MouseDown event but requires here the Shift key to be pressed also. Therefore, you must hold the Shift key down before you drag the zoom rectangle. Moreover, the zoom rect must be dragged in top-left to bottom-right direction although the vertical drag bars seem to indicate that this might not be required here. Otherwise there is no zooming at all. But I guess this is not your problem because you do see zooming, but delayed by a few seconds - right?
Lazarus trunk / fpc 3.0.4 / all 32-bit on Win-10

mig-31

  • Sr. Member
  • ****
  • Posts: 260
Re: Increase TAChart drawing performence
« Reply #4 on: September 12, 2019, 10:26:23 am »
Yes, your are rigth. I see a few second delay, when I do zoom drag and refresh delay.

On my PC I also see the difference beetween a time needed to refresh chart, when I push Time refresh button in LineDemo example. In case of my demo modification in full screen 1680x1050 time refresh is 0.955 second. In case of standard demo is 0.2 second.
Lazarus 2.0.2 - CentOS 7.x, Mageia 7.1

wp

  • Hero Member
  • *****
  • Posts: 6362
Re: Increase TAChart drawing performence
« Reply #5 on: September 12, 2019, 11:25:10 am »
OK, I see this too now. But I think there's nothing to be done against this difference: In your demo almost every pixel of the screen is painted because the series largely overlap. In the original demo the series are well-separated and only a small fraction of the screen is painted. Because TAChart does not paint coincident pixels there is a larger chance that this optimization will have an effect with the original demo than with your demo.

I am not sure if this observation is related to the issue in your project on the first post where you have 16 * 7000 = 112,000 points at smaller screen coverage, but the time delay is a "few seconds" opposed to the 1 second here with 10 times more points and almost complete screen coverage.
Lazarus trunk / fpc 3.0.4 / all 32-bit on Win-10

mig-31

  • Sr. Member
  • ****
  • Posts: 260
Re: Increase TAChart drawing performence
« Reply #6 on: September 12, 2019, 11:38:10 am »
I will make a test of time refresh like in LineDemo in my project and post result here: number of TLineSeries, number of points, because "few seconds" is not a presize unit.
For me it will be a good result if zoom drag and pan drag smooth with 16 * 7000 points.

Do you think, if I installed  external video card drawing will be faster?


Lazarus 2.0.2 - CentOS 7.x, Mageia 7.1

wp

  • Hero Member
  • *****
  • Posts: 6362
Re: Increase TAChart drawing performence
« Reply #7 on: September 12, 2019, 11:59:19 am »
No, there's something wrong in your code.

In the attachment there is a demo which shows that 16 series with 7000 points are almost drawn instantly (0.05 s on my system), zooming into a 100 point-wide region is negligible.

You must try to find out what is different in your code from this demo. It would be helpful if you could somehow remove the non-charting-related details and post the remaining project.
Lazarus trunk / fpc 3.0.4 / all 32-bit on Win-10

mig-31

  • Sr. Member
  • ****
  • Posts: 260
Re: Increase TAChart drawing performence
« Reply #8 on: September 12, 2019, 06:34:04 pm »
As I see your demo project is smooth enough and probably there is something in my project, which reduce performance.

Please find in attachment my  project,  where I removed unimportant data acquisition part.

Project creates configuration directory with 3 files in the default user configuration directory (under Linux /home/<user name >/.config/test).

Thanks for any idea.

Lazarus 2.0.2 - CentOS 7.x, Mageia 7.1

mig-31

  • Sr. Member
  • ****
  • Posts: 260
Re: Increase TAChart drawing performence
« Reply #9 on: September 12, 2019, 06:34:35 pm »
There is a test.txt file in zip file for loading data into charts through menu File -> Open file.
Lazarus 2.0.2 - CentOS 7.x, Mageia 7.1

wp

  • Hero Member
  • *****
  • Posts: 6362
Re: Increase TAChart drawing performence
« Reply #10 on: September 12, 2019, 10:42:55 pm »
Thanks for providing project and test file. Unfortunately there are no data plotted here. I did this:

- Unzip project to a folder
- Unzip data file to the same folder
- Open the project in Laz
- I see in the project options that there is a missing unit (defaultdevicesaliasedit) - I removed it.
- Compile - crashes because of clocale in main unit's uses (I am on Windows) - I removed it.
- Compile again and run. Successful.
- Click "File" > "Open". I select "test.txt" for opening
- File loads successfully - file name is displayed in title bar of the main window.
- BUT: Table on page "Overview" is empty (should it?), pages "Reverse Current", "Blocking Current", "Temperature", "Reverse and blocking voltage" and "Waveforms" display empty charts.

Is something missing? Or does the program only work on Linux?
Lazarus trunk / fpc 3.0.4 / all 32-bit on Win-10

mig-31

  • Sr. Member
  • ****
  • Posts: 260
Re: Increase TAChart drawing performence
« Reply #11 on: September 13, 2019, 09:58:01 am »
Hi,
thank you for replay.  Project is multiplatform, but I have not checked it under Windows.
I will checked it under Windows 7 and post the project again.

Thank you.
Lazarus 2.0.2 - CentOS 7.x, Mageia 7.1

mig-31

  • Sr. Member
  • ****
  • Posts: 260
Re: Increase TAChart drawing performence
« Reply #12 on: September 13, 2019, 11:15:26 am »
There is a test project, which I checked under Windows 7.
As I see under Windows 7 zoom in is smooth and zoom area appears immediately, but zoom out needs some time to redraw 0.5 - 0.9 seconds.
Under CentOS 7 Qt4 widget drawing of zoom in rectangle is not smooth.

I fill that is because PC Windows7  CPU has more power compare to PC CentOS7  CPU .
Lazarus 2.0.2 - CentOS 7.x, Mageia 7.1

wp

  • Hero Member
  • *****
  • Posts: 6362
Re: Increase TAChart drawing performence
« Reply #13 on: September 13, 2019, 03:24:18 pm »
I don't see any serious mistake here. But I have to confirm that, on Windows, this project zooms in instantly, but zooming out takes a noticable time, maybe in the order of a second. We had this recently (https://forum.lazarus.freepascal.org/index.php/topic,46536.msg331931.html#msg331931): for fast drawing it is recommended to stay with LineSeries.LinePen.Width = 1, but you set it to 2. Switching to 1 will speed up at least the Windows performance significantly

I cannot confirm the issue on Linux Mint/gtk2. No idea about CentOS, I don't have it.

Please test Pen.Width = 1 in your original project under CentOS and report back.
« Last Edit: September 13, 2019, 03:52:43 pm by wp »
Lazarus trunk / fpc 3.0.4 / all 32-bit on Win-10

mig-31

  • Sr. Member
  • ****
  • Posts: 260
Re: Increase TAChart drawing performence
« Reply #14 on: September 16, 2019, 11:35:54 am »
Thank you wp, when I set LinePen.Width=1 speed up under CentOS7 Qt4 widget set is the same like in Windows. There is no delay. Result under GTK2 is the same as Qt4. With LinePen.Width=2 GTK2 is a little faster. I have tested project compiled Qt5 widget on my home PC with Nvidia GTX1600 card and zoom in/out  was smooth.
 

I'm so sorry, that I don't read TAChart documentatio so carefully, where is mention to set LinePen.Width to 1 to speed up drawing.

What is the state of OpenGL drawing of TChart? It still needed to creation TChart with standard drawer before using OpenGL drawer?


Lazarus 2.0.2 - CentOS 7.x, Mageia 7.1