Read an Excerpt
Chapter 13: Creating Charts and Graphs
In this chapter, you will learn to use a new feature of ColdFusion 5: the ability to create charts and graphs on the fly. As a result of the Macromedia acquisition of Allaire, ColdFusion now includes the Macromedia Generator graph-generation engine. This allows ColdFusion to create bar, line, and pie charts on demand. This allows you to create Web pages that present data graphically without creating graphics in advance.In addition, you can create charts and graphs from dynamic data, such as the result of a database query. This makes the charting capabilities even more powerful: Users can always see charts or graphs reflecting the latest available data for your application.
This chapter provides a brief overview of the advantages of graphing data and how graphs in ColdFusion work and then proceeds to show you how to create graphs and charts manually and dynamically.
Why Graph Data?
Too often, data is presented in text format to users, perhaps in the form of a table. But, with most numerical data, users are better able to see the relationship among the numbers through a visual presentation.For instance, consider a simple example: a small university tracks the number of students from each continent. It does this to get a sense of its student body's diversity. This data can be presented as raw numerical data (see Figure 13.1).
It is hard to quickly get a sense of the relative sizes of the student body from each continent from this table. This is improved slightly by reporting percentages instead of raw student numbers (see Figure 13.2).
By displaying the results in a pie graph, it is easy to quickly see the relationship of the number of students from each continent without having to pay detailed attention to the specific numbers: the relative size of the pie slices conveys sufficient information to get a qualitative feel of the diversity of the student body (see Figure 13.3).
The problem of data visualization becomes even more acute with more complex data sets. At a certain point, tables of numbers become veils that hide the meaning of the data: Graphical presentation can pierce those veils and ColdFusion 5's graphing and charting capabilities provide a simple way to achieve this.
Graphs in ColdFusion
ColdFusion's graphing capabilities are provided by the Macromedia Generator engine and the JRun Java server, both of which are included as part of ColdFusion 5. To be able to create graphs in ColdFusion, you will need to be sure both of these are installed. Normally, they are installed by default when you install ColdFusion 5. If you opted not to install them, rerun the ColdFusion installation process and update your installation to include these components.
Types of Graphs
ColdFusion can generate several types of graphs:
Bar charts Graphs representing data as a series of vertical bars (see Figure 13.4)Horizontal bar charts Graphs representing data as a series of horizontal bars (see Figure 13.5)
Line graphs Graphs representing data as a series of points connected by a line (see Figure 13.6)
Area graphs Graphs representing data as a series of points connected by a line with the area under the line shaded (see Figure 13.7)
Pie charts Graphs representing data as slices of a complete circle (see Figure 13.8)....