Recent

Author Topic: Show on chart whats on grid  (Read 2966 times)

daveinhull

  • Sr. Member
  • ****
  • Posts: 297
  • 1 divided by nothing must still be 1!
Show on chart whats on grid
« on: March 05, 2019, 03:16:53 pm »
Hi,

I'm just not sure where to start but I'd like to be able to show what is currently visible on a grid on a bar chart. Say the grid shows 40 visible entries then I'd like these to be displayed on the chart. As the grid is moved down, then the chart also moves with the grid.

Is this possible?

Many thanks
Dave
Version #:1.8.4 Date 2019-01-08 FPC Version: 3.0.4 and SVN Revision 57972 for x86_64-win64-win32/win64

wp

  • Hero Member
  • *****
  • Posts: 11858
Re: Show on chart whats on grid
« Reply #1 on: March 05, 2019, 04:04:36 pm »
Look at the attached demo. It uses a TUserDefinedChartSource which reads the numbers from the grid and passes them to the series via the event OnGetChartDataItem. Whenever the grid is scrolled or resized a procedure UpdateChart is called which tells the UserDefinedChartSource how many rows are visible and resets it to update the plot. Data extraction begins at the row specified by the TopRow property of the grid.

daveinhull

  • Sr. Member
  • ****
  • Posts: 297
  • 1 divided by nothing must still be 1!
Re: Show on chart whats on grid
« Reply #2 on: March 05, 2019, 04:19:05 pm »
Wow excellent, many thanks wp
Version #:1.8.4 Date 2019-01-08 FPC Version: 3.0.4 and SVN Revision 57972 for x86_64-win64-win32/win64

daveinhull

  • Sr. Member
  • ****
  • Posts: 297
  • 1 divided by nothing must still be 1!
Re: Show on chart whats on grid
« Reply #3 on: March 05, 2019, 07:43:29 pm »
Hi wp,

I've almost got it working, but having a few problems with RxDBGrid which has the data.
It doesn't have .Cells or .VisibleRowCount, it also doesn't have a TopLeftChanged event.

I can set the .VisibleRowCouint to a fix number as I won't be changing the actual grid, but I'm a little lost on the .Cells bit.
I guess I'll need to refer to the underlying DataSet and move this to get the values.
I could use the AfterScroll event, but this triggers even when the grid rows don't change.

Any thoughts?

Many thanks Dave 
Version #:1.8.4 Date 2019-01-08 FPC Version: 3.0.4 and SVN Revision 57972 for x86_64-win64-win32/win64

wp

  • Hero Member
  • *****
  • Posts: 11858
Re: Show on chart whats on grid
« Reply #4 on: March 06, 2019, 05:10:05 pm »
How large is the dataset that you want to display in the DBGrid, how many rows in total? If it's not too many I'd recommend to use a StringGrid instead of a DBGrid and copy the records from the dataset to the StringGrid as strings. Then you can proceed like I showed you before.

Having a DBGrid (I don't know RxDBGrid, but it is probably very similar) it is very difficult to keep track of the visible data and to extract only the visible part from the dataset.
« Last Edit: March 06, 2019, 06:53:02 pm by wp »

daveinhull

  • Sr. Member
  • ****
  • Posts: 297
  • 1 divided by nothing must still be 1!
Re: Show on chart whats on grid
« Reply #5 on: March 06, 2019, 09:32:25 pm »
The main database is about 1500 rows and this part of the app simply sums the main database into categories (using a database SQL query to get the results) which results in around 100 odd rows, so I think I'll go the way you suggest and copy the dataset into a StringGrid and then follow your code.

Thanks
Dave
Version #:1.8.4 Date 2019-01-08 FPC Version: 3.0.4 and SVN Revision 57972 for x86_64-win64-win32/win64

 

TinyPortal © 2005-2018