ColdFusion: Less Code, More Results

TheĀ primary reason why I prefer ColdFusion over other web app languagesĀ is the efficiency afforded in the programming stage. ColdFusion is a genuine Rapid Application Development (RAD) language. For example, to run a database query and draw a pie chart using the Google Chart API, takes about 20 lines of code and does not require additional libraries such as jQuery.

Here’s an image of the pie chart generated by the code below.

ColdFusion, Google Pie Chart
ColdFusion, Google Pie Chart

 

The following code is enough to generate a Google pie chart in ColdFusion.

<cfquery dbtype="query" name="qSelect_userPie">
select sum(totalMinutes) as tmin, ucase(dbUser) as dbUser from qSelect_userTime group by dbUser order by tmin desc, dbUser
</cfquery>
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
 <script type="text/javascript">
 google.load("visualization", "1", {packages:["corechart"]});
 google.setOnLoadCallback(drawChart);
 function drawChart() {
 var data = google.visualization.arrayToDataTable([
 ['db', 'CPU Time'],
 <cfoutput query="qSelect_userPie">
 ['#dbuser#', #round(tmin)#]<cfif currentRow lt recordCount>,</cfif>
 </cfoutput>
 ]);
 var options = {
 title: 'DB CPU Activity Last 24 Hours',
 // colors: ['orange','green','blue','gray','black','gold']
 };
 var chart = new google.visualization.PieChart(document.getElementById('chart_div'));
 chart.draw(data, options);
 }
 </script>
<div id="chart_div" style="width: 500px; height: 300px;"></div>

Enjoy!

Leave a Reply