There are powerful means to create diverse kinds of graphs built in Coldfusion, including Flash-based ones. But they of course would take more time to initialize than simple HTML-based graph if you need to show some simple graph on public side of your website where performance optimization is critical. Also it is possible to get fully custom visual graph, for instance I made bars using color gradient in Photoshop. For this goal I built pretty simple Coldfusion component-based function named "Utilization Graph". It accepts the following parameters: - Current value;
- Total value;
- Graph width;
- Format (dollars / percents / plain numbers), applies to label
- "Show 'from'" - if set to TRUE, will show total in label, like this: "25 from 90"
This component is available for free download. Source code: <CFFUNCTION name="UtilizationGraph" returntype="void" output="Yes"> <CFARGUMENT name="current" type="numeric" required="Yes"> <CFARGUMENT name="total" type="numeric" required="Yes"> <CFARGUMENT name="scaleto" type="numeric" required="No" default="100"> <CFARGUMENT name="format" type="string" required="No" default="999999999.99"> <CFARGUMENT name="showfrom" type="boolean" required="No" default="yes"> <CFPARAM name="REQUEST.cfcimgpath" default="images"> <CFIF ARGUMENTS.total> <CFSILENT><CFSET k=(ARGUMENTS.scaleto/ARGUMENTS.total)></CFSILENT> <TABLE cellspacing="0" border="0"> <TR><TD><IMG src="#REQUEST.cfcimgpath#/appstyle/horbar2.gif" width="#int(evaluate(ARGUMENTS.current*k))#" height="12" border="0" alt="#ARGUMENTS.current#%" title="#ARGUMENTS.current#%"><IMG src="#REQUEST.cfcimgpath#/appstyle/horbar1.gif" width="#int(evaluate('(ARGUMENTS.total-ARGUMENTS.current)*k'))#" height="12" border="0"></TD> <TD> <CFIF ARGUMENTS.format is "$"> #dollarformat(ARGUMENTS.current)#<CFIF showfrom> from #dollarformat(ARGUMENTS.total)# </CFIF> <CFELSEIF ARGUMENTS.format is "%"> #int(ARGUMENTS.current)#% <CFELSE> #trim(numberformat(ARGUMENTS.current,"#ARGUMENTS.format#"))#<CFIF showfrom> from #ARGUMENTS.total#</CFIF> </CFIF> </TD></TR> </TABLE> </CFIF> </CFFUNCTION> |
| |
| BRIEF DESCRIPTION: Coldfusion open source: function to display percent of total (graph) - "Utilization Graph". Free Coldfusion code examples, coldfusion tutorial |
|
|
| |
Add your review to this item: |
|
|
|
|