• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 765
  • Last Modified:

Graphs in Turbo Pascal v. 7

To Hypo,
Hi there, I have deleted my previous question as I have 'sorted' it- if you'll excuse the pun. However I have another question which believe is quite difficult to solve- for me at least. I have now arrived at one of the last procedures in my project which is to create a graph trend of my two input files covering the transactions over the year. One axis displays the months and the other is divided by the two files with '0'set between the two. At the end of each month The balance is read from both files and entered onto the graph showing the cashflow position between the two files relative to '0'. If the Income files decends into the expenditure and the expenditure into the Income half the result is a deficit.
I have toiled over this problem for the whole week and cannot see how to format this from my record files and produce a graphical picture of these events from the files of records.
Best wishes and hope you can help
  • 6
  • 5
  • 2
1 Solution
Personally I am not familiar with the rest of your project, but I assume you are trying to graph the cash flow.  So your graph would be the function of

F(month) = Income(month) - Expenditures(month)

....or is it something a bit more complicated than this?
chrisbeeAuthor Commented:
To Scrapdog,
Hi There!

Nice to hear from you. Yep! your right, It is hellishly complicated as far as I'm Concerned and here's the layout.
I have four files in my project. 1. record file of Income, 2.record file of Expenditure. 3.record file of direct debits. 4. record file of Date.

File of income/expenditure/direct debits are for user input from batched receipts each week ect;. The direct debits are input by the user for the period of one month. and can be edited as and when they please. Each time the user opens the program from then on, the date file compares the dates from the direct debit file and as each record comes into range each month, writes each one to the expenditure file which can be totalled each month along with the miscelaneous cashflows input by the user. At the end of the year the program will display a graph depicting the trends of both files relating to each month's final balance before the next income point with both files divided and relating to zero.
      Jan | Feb | Mar | ect;
value   -     _           -
value              -      
value   _    -      
value              _      -

The graph will show the trend of the balance and indicate which months were heaviest on the home resources and those which were lightest. I'm sorry if this is longwinded. I am at present engaged in writing the procedure to pass the direct debit values to the expenditure file which is proving a little tiresome- perhaps I should have put that question first, However they are both inportant to my project and folowing their completion will leave just the validation to do on the program. If it would help I can email the prog for you look at, the structure of which would give you some idea of what I'm up to. Anyway thank you for your interest and help.
Best wishes..........chrisbee.
Yes..e-mail it to scrapdog@jvlnet.com
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

What youneed is an histogram. It's easy to do using the Rectangle() procedure.

As Rectangle need coordinates of extremes in pixels (depending on screen resolution), you have to determine the scale factor which maps your screen to the graph to be plotted. After doing that, it's a stupid thing.
chrisbeeAuthor Commented:
To Viking,
Hi there! Thanks for your comments, I'm not familiar with histograms but your comment has sent me into my books. Like I said to Scrapdog my programming ability is limited at present having started in september of last year on 'A' level. My screen resolution is 600x800. Thanks for your help.
best wishes.........chrisbee.
>>My screen resolution is 600x800.

That will fall to 640 x 480 when working with graphic routines provided by TP.

Anyway, you need to map your screen to actual values to be represented, something like this:

Declare constant values for your real world:
        XMax = <your maximum X >
        YMax = <and Y values   >

Load screen limits:

Determine adjust factor to map screen:

Then, once you have a given (X,Y) pair, you can use a procedure like this to transform real world coordinates into pixel coordinates. Also, it rearranges the values in order to use the well-known lower-left corner as origin of coordinates (the actual origin of screen is at upper-left corner):

Procedure Adjust(x,y:single);
{ Receives: x and y as real values of real world
  Returns : ix and iy as integer pixel
  coordinates }
chrisbeeAuthor Commented:
Thank you Viking for your advice though it is still way above my head. However I shall try and create the graph format with the sample code you have given me and am reading up on the rectangle procedure- this is different Pascal than what I have been used to.
I'm sorry if I frustrate your efforts and your patience.
Best wishes............chrisbee.
It's easy if you think of your screen as if it were a squared sheet of paper.

My poor English keeps me aside a bit from the exact meaning of several words of your former question, but let's supose you want to draw a histogram showing the monthly transactions of your company.

Coordinates represent real-world values, so:
- The highest rectangle (this is, the
  highest transaction rate of the whole
  process); is the maximum Y value;
  thus, the height of the screen will
  represent that value.
  Therefore, YMax := <this value>

- X axis will hold enough space for
  hold one month. Then, XMax := 12

When you want to draw a rectangle for a given month, its corners are representd by:

Whole procedure is: Rectangle (ulx, uly, lrx, lry) where

ulx = upper left X
uly = upper left Y
lrx = lower right X
lry = lower right Y

Those four values define two corners: upper left and lower right, which is enough to draw the so defined box.

Then, taking your values, we have:
ulx = <month number - 1>
uly = transaction rate (depending on month)
lrx = <month number>
lry = 0 (zero)

But, as you need to map real world coordinates into screen coordinates, the aforementioned Adjust() procedure make the job, and then:

Adjust(Month - 1 , HigestValue);

  this returns ix and iy, which you must copy into another variables, lets say, ix1 and ix2, so

ix1:=ix; iy1:=iy;

   these are upper left coordinates. Now, you do the same with lower right:

Adjust(Month, 0);

Now, a call to the marvelous procedure:

Rectangle(ix1, iy1, ix, iy);

and voilá !!, a rectangle appears representing the transaction rate of that month.

Of course, you can play with different colours, fill patterns and other effects, but that's your assignment... :)

>> X axis will hold enough space for
  hold one month. Then, XMax := 12

Opps !!!!, correct that to read:

X axis will hold enough space to hold the whole year.

chrisbeeAuthor Commented:
To Viking,

Hi There! You have made it much clearer now, I still have some reading-up to do on what you have demonstrated here and realise I have to start somewhere. What I want to do is this-

In the upper half of the rectangle I want to place the income,

0.........to maxvalue,
through the middle of the rectangle runs the base line '0' (zero)

In the lower half of the rectangle I want to place the expediture,

0..........to max value, I hope then it will look like this-

income- Jan-Feb-Mar-Apr-May-Jun-Jul-ect;

As each Month's transactions are entered The top half of the graph shows the maximum income for that month and the bottom half of the graph shows the expenditure put against the income. as the graph of expenditure approaches the base line zero it indicates the resources available for that month and if it crosses it, then a deficit esists on the account,

Can I produce such a graph with the rectangle procedure or would I need to use two rectangle procedures simultaneously? Thanks for the psuedo code and will have a go at putting it together over this weekend and at college. Would you please verify, that, what I have written in this comment is online with what you have suggested- the next time I come in, the points are yours. Thanks so much for your help.
Best wishes ..........chrisbee.
Of course,you can locate X axis at the middle of the screen. In that case, you must correct Adjust() procedure to return adequate values.

To draw each portion of the screen (upper and lower), you must use separate Rectangle() procedures.
chrisbeeAuthor Commented:
Thanks Viking I shall try it out. I have all your comments as a guide.
Best wishes.............chrisbee.
Glad to have helped you (and thnx for the points !!).

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 6
  • 5
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now