Simple CFCHART/jQuery Demo

I had some time to kill today and I decide to mix cfchart up with some jQuery love. You can see the demo of this here. When the chart loads, click on the bars, and you will see a detail load beneath the graph.

The code behind this is fairly trivial. I've got a file I include to generate my chart data. Normally this would be a proper database query. The main template's code consists of:

<cfinclude template="data.cfm">

<script type="text/javascript" src=""></script> <script> function loadData(l) { $("#detail").load('detail.cfm?name='+escape(l)).hide().fadeIn('slow') } </script>

<cfchart chartWidth="500" chartHeight="250" format="flash" url="javascript:loadData('$ITEMLABEL$')"> <cfchartseries type="bar" query="data" itemcolumn="name" valuecolumn="sales" /> </cfchart>

<div id="detail" style="width:500"></div>

The cfchart makes use of the url attribute to specify what should happen when you click. In this case, I'm simply calling a function, loadData(). This then uses jQuery to make a remote call to detail.cfm. Note that I pass the name. Normally you would pass a primary key, but we don't have (easy) access to that (see this entry for more info) value so we have to work with the name instead. That's it. All detail.cfm does is look up the detail information:

<cfinclude template="data.cfm">

<cfparam name="" default="">

<!--- get detail based on label ---> <cfquery name="detail" dbtype="query"> select * from data where name = <cfqueryparam cfsqltype="cf_sql_varchar" value=""> </cfquery>

<cfif detail.recordCount is 1>

Founded: #detail.yearfounded#&lt;br/&gt;
Sales: #dollarFormat(detail.sales)#&lt;br/&gt;


Not terribly useful I guess, but fun.

Like This?

If you like this article, please consider visiting my Amazon Wishlist or donating via PayPal to show your support. You can also subscribe to the email feed to get notified of new posts.