Data are often available in the form (date, "value"), which need to be presented graphically. A typical application is the graphing of share prices over a period of time. It is often helpful to present such data on a logarithmic, (rather than a linear) scale, for which the advantages may be:
The QBasic LOGCHART.BAS program described below started life as part of a suite of programs written to record and analyse a portfolio of share transactions, and provided graphs of share price against time, with "value", the latter in terms of dollars and cents. For the present purpose, "value" is of the generalised form y = nn.nn, and the y axis is designated "Y", instead of dollars. Any date of the form dd/mm/yy (including "today") may be chosen from the time span of the data file, from which to "look back" over the "values" recorded in the file. A feature of the program is the automatic selection of one of four output charts, according to the data value at the "look-back-from" date. The ranges of "value" available are 0.1 to 1, 0.3 to 3, 1 to 10 and 3 to 30. Other ranges could be added, of course. The program The program was written with the expectation that it would be used on a data file comprising integer "n" (the number of entries in the file) followed by n 13-byte string entries of the form dd/mm/yy (8 bytes) + nn.nn (5 bytes). In the following description, figures such as [1] refer to the corresponding
blocks in Figure 2. On "run", the screen asks for the path and file name of the data file [1], and this is stored in memory [2]. Next, the user is asked to enter a "look-back-from" date (within the known range of the data, of course), or to press any key if the answer is "today". In the latter case, the computer's DATE$ (mm/dd/yy) is converted to dd/mm/yy [4]. The "value" for the entered date is now compared with the (logarithmic) middle of each of the available ranges, and a range is selected in which the difference is a minimum. This places the latest-date plot of "value" midway between the maximum and minimum positions of the selected scale. For example, the middles of each of the four (logarithmic) ranges are:
For all of the y ("value") scales, the x (horizontal) scale is presented as 0 weeks (back from the selected look-back-from date), at the right-hand end of the screen, to 100 weeks back. Vertical dashed lines are drawn to form markers at 20, 40, 60, 80 and 100 weeks. The look-back-from date is shown, together with the file name, below the x axis. The horizontal markers for block [7.1] are drawn in dashed equally-spaced lines at y = 0.1, 0.15, 0.25, 0.4, 0.65 and 1.0. Similarly, the corresponding lines for block [7.3] are drawn at ten times these values. The horizontal markers for block [7.2] are drawn in dashed equally-spaced lines at y = 0.3, 0.45, 0.75, 1.2, 2.0 and 3, with the corresponding lines for block [7.4] drawn at ten times these values. In the final block [8], the latest-date x,y
plot is made first, then a line connects it to the next-latest, and so on, until the earliest plot is made.
The resulting graph is retained until the program is completed by pressing any key. A sample plot of dollar
values over two years in shown in Figure 1.
Availablity LOGCHART.BAS
could be incorporated as a subroutine in a parent program. It is fully commented and ican be downloaded as LOGCHART.BAS. |