Instead of building an array and then populating it with sparse data, you can mark a drawing with the data points as you create it. This technique is used to create two graphing calculators: one that handles a single complex expression and one that uses a different color for each of two complex expressions. Along the way, you'll use nested cfoops and stretch simple images to paint XY graphs.
Images paste together nicely into a large rectangle. You can even use a line break to start a new line. Just don't put any space between the tags that produce the images and don't mix text and images on the same line. Try putting a few images of the same size side-by-side on a line and then allow space between the tags. When you do this, you'll see why they have to be jammed together (even though it makes the code in the display block hard to read).
When you put a few rows of images together, you'll notice that it doesn't look good to let "points" touch on the diagonal; they look like crepe paper streamers instead of lines. To avoid this effect in these examples, each row that may contain points is followed by a row that does not (so that only alternate rows have points), and the images (blue-red, blue-green, or blue-blue consist of color pairs to keep adjacent points on the same row from touching (so that only alternate columns have points). The image fill is not complete for equations representing two-dimensional solids, but the meaning is clear.
For the one-expression calculator, define one field. The sample expression shows that the field is intended to accept ColdFusion operators such as "is" and "or".
<cfif not isDefined("form.test")>
<cfset test="(x-2)/2 + 1 is y or x-8 is y">
<cfelse>
<cfset test="#form.test#">
</cfif>
For the two-expression calculator, add a variable for one more field. The familiar equation for a circle is less familiar when an exponent is not used, but ColdFusion doesn't like it when the number being raised to an exponent might be zero.
<cfif not isDefined("form.test2")>
<cfset test2="(x-15)*(x-15) + (y-7)*(y-7) is 25">
<cfelse>
<cfset test2="#form.test2#">
</cfif>
<cfform name="graph" action="grapha.cfm" method="post"> <cfinput type="text" name="test" value="#test#" size="62" maxlength="60"> <input type="submit" name="" value="Submit"> </cfform>
The two-input calculator's form looks like this. Notice that the form action is different (so you can have two different calculators). Otherwise, the only difference between this form and the previous one is the additional input field.
<cfform name="graph" action="graphb.cfm" method="post"> <cfinput type="text" name="test" value="#test#" size="63" maxlength="60"> <cfinput type="text" name="test2" value="#test2#" size="63" maxlength="60"> <input type="submit" name="" value="Submit"> </cfform>
<cfset hmax=50> <cfset vmax=20> <cfloop index="y" from="#vmax#" to="1" step="-1"><cfloop index="x" from="1" to="#hmax#" step="1"><cfif evaluate(test)><img src="br.gif" width="9" height="5"><cfelse><img src="b.gif" width="9" height="5"></cfif></cfloop><br><img src="b.gif" width="450" height="5"><br></cfloop>
Try the first calculator out by creating the images and then copying the single-image definition, form, and graphing block into a single file; this example calls it grapha.cfm. If the output has gaps, review what you've copied. If there are gaps or line breaks between tags in the graphing block, remove them.
Then try the second calculator, graphb.cfm. Here is its graphing block. The only difference is the addition of bg.gif to use a different color for the points of the second expression as needed.
<cfset hmax=50> <cfset vmax=20> <cfloop index="y" from="#vmax#" to="1" step="-1"><cfloop index="x" from="1" to="#hmax#" step="1"><cfif evaluate(test)><img src="br.gif" width="9" height="5"><cfelseif evaluate(test2)><img src="bg.gif" width="9" height="5"><cfelse><img src="b.gif" width="9" height="5"></cfif></cfloop><br><img src="b.gif" width="450" height="5"><br></cfloop>
However, if you absolutely have to show proportions, try using a single bar which contains many colors: one for each portion being represented. The proportion will show even more clearly than with a pie chart and will take up less screen real estate.