Bottom     Previous     Contents

13 Drawing pie charts

13.0 Introduction

13.1 Drawing a pie chart

13.2 Activities

13.3 Storing a pie chart

13.4 Activities

13.0 Introduction

A pie chart is a display which shows the relative amounts of things which make up a whole. The whole is represented by a complete circle, and each of the other quantities is represented by a segment of the circle. With a pie chart, it is easy to see proportions at a glance - something which is not so easy from a table of numbers.

Screen Display 13.1 (first part)

Screen Display 13.1 (second part)

This chapter shows how to draw pie charts. The programs rely on PROCpie which is one of the procedures which we provide. It draws a pie chart from data which you supply and of a size and positioning which you dictate. Like our other procedures PROCpie is given in Appendix I and is also available ready-recorded on cassette tape.

13.1 Drawing a pie chart

Screen Display 13.1 shows a pie chart for how a person might chose to divide up £1500 when buying a computer system. As a list, the figures are:

Model B BBC Computer £399
Disk interface £105
Disk drives £295
Colour monitor £280
Printer £350
Miscellaneous £71
TOTAL £1500

Compared with this list, you will probably agree that the division of resources is more obvious at a glance from Screen Display 13.1.
Listing 13.1 gives the program for producing Screen Display 13.1. Lines 100 and 110 ask the user for the radius and centre of the required pie chart. This data is fed in via INPUT statements which provide for a dialogue between the computer and a user. (Our data is underlined to distinguish it from the computer's part of the dialogue. You could of course input yours instead of ours.) When you come to do so, we suggest that you identify the centre of the pie chart with addressable points around 600, 500, and that you choose a radius of something less than 400. All of these measurements are in screen co-ordinates, as measured in addressable points (see Section 1,4), The rest of the program relies on PROCpie which takes care of drawing the display.

Screen Display 13,2

13.2 Activities


i. Run the program of Listing 13.1 using your own data. ii. Draw several pie charts, each one at a different position on the screen and with a different radius.

iii. Can you accommodate a long sector name by specifying a new centre to move the pie chart sideways?


13.3 Storing a pie chart

When the data is fed in as INPUT statements, the resulting pie chart cannot easily be stored. You may therefore prefer to use DATA statements instead. Not only do they allow for easy storage, they are also easy to edit. Furthermore this means of programming makes it easier for you to add your own extras to the display. You could, for example, put in a title.

Screen Display 15.2 shows the relative areas of parts of the United Kingdom using the following data:

England 131000 square kilometres
Wales 21000 square kilometres
Scotland 79000 square kilometres
N.Ireland 14000 square kilometres

The data is stored in DATA statements and the complete program is given in Listing 13.2. This program works in the same way as that for Listing 13.1, apart from how the data is fed in. With this sort of program, you can load it, and keep editing and experimenting until you are completely satisfied with the display.

13.4 Activities


i. Run the program of Listing 13,2 using some data of your own. ii. Experiment with the positioning and labelling until you are satisfied with the result.



Next     Top