Microsoft Word - Core PHP Programming Using PHP to Build Dynamic Web Sites

(singke) #1

from a form is probably not a practical idea for large amounts of data. The GET method
imposes a relatively small limit on the total size of a URL that varies between Web
servers. You could use the POST method, however. The two examples I'll show are a bar
graph and a pie chart. Each uses the same set of data, which is a fictitious survey of
favorite meat.


Bar Graphs


Bar graphs are a good way to compare values to each other. Creating them is a relatively
simple task because each data point is a rectangle. The height of the rectangle represents
the value of the data point. To make the transition, a scaling factor is used. In Listing
19.3 the graph is 200 pixels tall and the scaling factor is two. This means that a data
point with the value 75 will be 150 pixels tall.


The business of creating the graph is similar to the process described above where a
button is created. A blank image is created, several colors are allocated, and functions are
called for drawing shapes into the image. The script allows the width of the bars to adapt
to the width of the graph. The width of the graph is divided by the number of bars drawn.
A ten-pixel gutter is drawn between the bars. In the center of the bar the data point's label
is written along with its value.


Listing 19.3 Creating a Bar Graph

Free download pdf