Recent

Author Topic: [SOLVED] Canvas Plot vanishes  (Read 391 times)

J-G

  • Hero Member
  • *****
  • Posts: 953
[SOLVED] Canvas Plot vanishes
« on: October 08, 2022, 01:03:04 pm »
I wish to show a very simple graph of historic data only under certain conditions.

Under 'normal' running the project does not need to show some data but when [Rates] change then the size of the [Form] can be expanded to reveal extra input fields. This has been working perfectly (and still does as far as data entry is concerned) but I would now like to show a graph of the historic [Rates].  Very simple -- create a TPanel, adjust the data points to fit and plot with MoveTo & LineTo.

Stepping through I can see that the graph is drawn exactly as I would expect but upon completion, the graph disappears ?  -  The attached ScreenGrabs show the state (9) at the end of the plot routine and then (9A) at the next [F9].

I tested my logic by writing a small test with just a TPanel and TButton. With the form full size, the display is perfect. When I make the form small - so that only the Button is initially visible - then add the form height change before the plot routine, again the plot shows during a step through but vaishes as soon as the project completes. (attached image SG10)

This led me to check if application.ProcessMessages - placed immediately after the form expansion - might solve the problem  - - -  it doesn't.

Can anyone explain what I need to do to solve this?


« Last Edit: October 08, 2022, 03:00:39 pm by J-G »
FPC 3.0.0 - Lazarus 1.6 &
FPC 3.2.2  - Lazarus 2.2.0 
Win 7 Ult 64

wp

  • Hero Member
  • *****
  • Posts: 11923
Re: Canvas Plot vanishes
« Reply #1 on: October 08, 2022, 02:04:59 pm »
In which event do you draw the plot? In something like an OnClick event? This is wrong because this plot would not be persistent. Imagine the user drags another window over your plot and the OS requests the plot to redraw itself - then the OnClick instructions will no longer be available! Only draw in the OnPaint event of the panel. Or create a buffering bitmap in which you create your plot, and which you draw on the panel's Canvas in the panel.OnPaint event.

Are you aware that Lazarus contains a very powerful plotting library, TAChart? https://wiki.lazarus.freepascal.org/TAChart_documentation, https://wiki.lazarus.freepascal.org/TAChart_Tutorial:_Getting_started

J-G

  • Hero Member
  • *****
  • Posts: 953
Re: Canvas Plot vanishes
« Reply #2 on: October 08, 2022, 02:22:07 pm »
In which event do you draw the plot? In something like an OnClick event? This is wrong because this plot would not be persistent. Imagine the user drags another window over your plot and the OS requests the plot to redraw itself - then the OnClick instructions will no longer be available! Only draw in the OnPaint event of the panel. Or create a buffering bitmap in which you create your plot, and which you draw on the panel's Canvas in the panel.OnPaint event.

Are you aware that Lazarus contains a very powerful plotting library, TAChart? https://wiki.lazarus.freepascal.org/TAChart_documentation, https://wiki.lazarus.freepascal.org/TAChart_Tutorial:_Getting_started

SOLVED !  -  in fact about a minute before your post wp - for which thanks -  I had put the Application.ProcessMessages after the plot routine  :-[   When I put it in the correct place - immediately before the [Plot] -  the graph does appear correctly.

I am very aware of the TAChart and use it extensively in this project, but for plotting a single line of less than 20 points it's way over-kill - I only need to show the trend.
FPC 3.0.0 - Lazarus 1.6 &
FPC 3.2.2  - Lazarus 2.2.0 
Win 7 Ult 64

 

TinyPortal © 2005-2018