<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>But what if... &#187; Coldfusion</title>
	<atom:link href="http://eremiya.net/category/coldfusion/feed/" rel="self" type="application/rss+xml" />
	<link>http://eremiya.net</link>
	<description>Just another WordPress weblog</description>
	<lastBuildDate>Wed, 30 Jun 2010 04:00:38 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Jquery, Flot Tutorial (Part 2 revisited)</title>
		<link>http://eremiya.net/2010/06/30/jquery-flot-tutorial-part-2-revisited/</link>
		<comments>http://eremiya.net/2010/06/30/jquery-flot-tutorial-part-2-revisited/#comments</comments>
		<pubDate>Wed, 30 Jun 2010 01:59:13 +0000</pubDate>
		<dc:creator>Jérémie</dc:creator>
				<category><![CDATA[Coldfusion]]></category>
		<category><![CDATA[Jquery]]></category>
		<category><![CDATA[charting]]></category>
		<category><![CDATA[flot]]></category>

		<guid isPermaLink="false">http://eremiya.net/?p=149</guid>
		<description><![CDATA[Woaw, I&#8217;ve never blogged that much in a row. In my previous post, I showed you how to create a pod, and having ajax request to get the data. Actually, this is not the best way to use flot. Flot can redraw your chart &#8220;on the fly&#8220;, if I can say, if your code is [...]]]></description>
			<content:encoded><![CDATA[<p>Woaw, I&#8217;ve never blogged that much in a row. In my <a href="http://eremiya.net/2010/06/27/jquery-flot-tutorial-part-2/">previous post</a>, I showed you how to create a pod, and having ajax request to get the data. Actually, this is not the best way to use flot. Flot can redraw your chart &#8220;<em>on the fly</em>&#8220;, if I can say, if your code is written appropriately. <span id="more-149"></span></p>
<p>Let try to do that. As there is no great change on the  HTML file, let&#8217;s concentrate on the JavaScript. First, we define some global variables. When the page has loaded, we call a getData function, that takes 2 parameters, year and yearNumber.</p>
<pre class="brush: js">
var $j = jQuery.noConflict();

var plotarea = $j(&quot;#placeholder&quot;);

var months = [&#039;jan&#039;, &#039;feb&#039;, &#039;mars&#039;, &#039;apr&#039;, &#039;may&#039;, &#039;jun&#039;, &#039;jul&#039;, &#039;aug&#039;, &#039;sep&#039;, &#039;oct&#039;, &#039;nov&#039;, &#039;dec&#039;];

var &lt;cfoutput&gt;#toScript(url.year, &quot;year&quot;)#&lt;/cfoutput&gt;
var &lt;cfoutput&gt;#toScript(url.yearNumber,  &quot;yearNumber&quot;)#&lt;/cfoutput&gt;

$j(document).ready(function(){

//Draw the chart
getData(year,yearNumber);

//Put an event listener on every select of the form
$j(&quot;select&quot;).change(function() {

//Get the selects values
var selectedYear = $j(&quot;#year option:selected&quot;).text();
if (selectedYear == &#039;&#039;) {
selectedYear = year;
}
var selectedYearNumber = $j(&quot;#yearNumber option:selected&quot;).text();
if (selectedYearNumber == &#039;&#039;) {
selectedYearNumber = yearNumber;
}

getData(selectedYear,selectedYearNumber);

})

});
</pre>
<p>We also add event listeners on the selects of the control form. On Change, we get the value of both selects and call the getData function again. Let&#8217;s see that function.</p>
<pre class="brush: js">
function getData(year,yearNumber) {

var dataObject = [];

$j.getJSON(
&#039;http://dev.eremiya/flot/jquery_flot_1.5/charting.cfc?wsdl&#039;,
{ method : &#039;getStructForChart&#039;, returnformat : &#039;json&#039;, queryformat : &#039;column&#039;, year : year, yearNumber : yearNumber },
function(data) {

for (var a=0; a&lt;data.length; a++) {

eval(&quot;data&quot; + a + &quot; = []&quot;);

for (var i=0; i&lt;data[a].ROWCOUNT; i++) {

var myDate = new Date(data[a].DATA.ORDERDATE[i]+&#039;/01&#039;);
eval(&quot;data&quot; + a).push([myDate.getMonth(),data[a].DATA.TOTAL[i]]);
var dataYear = myDate.getFullYear();

}

dataObject.push({label:dataYear,data:eval(&quot;data&quot; + a)})

}

drawChart({data:dataObject});

}
)

}
</pre>
<p>The getData function call the CFC and get a JSON response. We format the data, and then we pass the populated data array to the drawChart function (as an option, if you noticed). The drawChart function takes options (you can overwrite them as you wish) and then, guess what&#8230;, draw the chart!</p>
<pre class="brush: js">
function drawChart(options) {

//Some option (edit for your own)
var defaults = {
data : [],
legend: {
show: true,
margin: 10,
backgroundOpacity: 0.5
},
points: {
show: true,
radius: 6
},
lines: {
show: true
},
grid: {
borderWidth:0,
labelMargin:15,
clickable:true,
hoverable:true,
autoHighlight:true
},
xaxis: {
tickSize: 1,
tickFormatter: function(val,axis) {
return months[val];
}
}
};

var options = $j.extend(defaults, options);

$j.plot(plotarea, options.data, options);

plotarea.bind(&quot;plotclick&quot;, function (event, pos, item) {

if(item != null) {
alert(&#039;In &#039;+item.series.label+&#039;/&#039;+item.datapoint[0]+&#039;, the order amout is &#039;+item.datapoint[1]);
}

});

}
</pre>
<p>As you can see, we are going to pass data as an option, and the drawChart function will redraw the chart without any refresh. That&#8217;s the magic of jQuery, Flot and ColdFusion. Here is the <a href="http://eremiya.net/wp-content/uploads/2010/06/jquery_flot_1.5_3.zip" target="_blank">source code</a> of this post (chart2.cfm). Change it to meet your needs. Again, this is by a newbie for newbies, so let me know if you have a better approach. We&#8217;ll progress together.</p>
]]></content:encoded>
			<wfw:commentRss>http://eremiya.net/2010/06/30/jquery-flot-tutorial-part-2-revisited/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Jquery, Flot Tutorial (Part 2)</title>
		<link>http://eremiya.net/2010/06/27/jquery-flot-tutorial-part-2/</link>
		<comments>http://eremiya.net/2010/06/27/jquery-flot-tutorial-part-2/#comments</comments>
		<pubDate>Sun, 27 Jun 2010 04:29:13 +0000</pubDate>
		<dc:creator>Jérémie</dc:creator>
				<category><![CDATA[Coldfusion]]></category>
		<category><![CDATA[Jquery]]></category>
		<category><![CDATA[charting]]></category>
		<category><![CDATA[flot]]></category>

		<guid isPermaLink="false">http://eremiya.net/?p=93</guid>
		<description><![CDATA[In my previous post, we created a chart that represent the increase of a given year by month (from january to december). In this post, we&#8217;ll see how to create a pod, for a dashboard for example, that uses the previously created page and gives the possibility to query for a special year, and also [...]]]></description>
			<content:encoded><![CDATA[<p>In my <a href="http://eremiya.net/2009/10/16/jquery-flot-tutorial-part-1-5/" target="_blank">previous post</a>, we created a chart that represent the increase of a given year by month (from january to december). In this post, we&#8217;ll see how to create a pod, for a dashboard for example, that uses the previously created page and gives the possibility to query for a special year, and also to display several years. Once again, we&#8217;ll use CFCs to query the database and get the data to our chart.</p>
<p><span id="more-93"></span></p>
<p style="text-align: center;">Here is a preview of what we want to achieve.</p>
<p><a href="http://eremiya.net/wp-content/uploads/2010/06/Screen-shot-2010-06-27-at-12.38.52-PM.png"><img class="aligncenter size-full wp-image-146" title="Pod" src="http://eremiya.net/wp-content/uploads/2010/06/Screen-shot-2010-06-27-at-12.38.52-PM.png" alt="" width="500" height="259" /></a></p>
<p>Let&#8217;s get started! First, a function to load the chart when our page has loaded:</p>
<pre class="brush: html">

&lt;div id=&quot;pod&quot;&gt;
&lt;!-- A div that will contain the cart --&gt;
&lt;div id=&quot;chartholder&quot; class=&quot;binding&quot; url=&quot;chart.cfm&quot;&gt;

&lt;/div&gt;

&lt;!-- Controller for our pod --&gt;
&lt;div id=&quot;dataCollector&quot;&gt;
&lt;cfoutput&gt;
&lt;form&gt;
&lt;label for=&quot;year&quot;&gt; Year :
&lt;select id=&quot;year&quot;&gt;
&lt;option&gt;&lt;/option&gt;
&lt;cfloop from=&quot;2000&quot; to=&quot;2004&quot; index=&quot;y&quot;&gt;
&lt;option value=&quot;#y#&quot;&gt;#y#&lt;/option&gt;
&lt;/cfloop&gt;
&lt;/select&gt;
&lt;/label&gt;

&lt;label for=&quot;yearNumber&quot;&gt; Number of year to display :
&lt;select id=&quot;yearNumber&quot;&gt;
&lt;option&gt;&lt;/option&gt;
&lt;cfloop from=&quot;1&quot; to=&quot;5&quot; index=&quot;n&quot;&gt;
&lt;option value=&quot;#n#&quot;&gt;#n#&lt;/option&gt;
&lt;/cfloop&gt;
&lt;/select&gt;
&lt;/label&gt;
&lt;/form&gt;
&lt;/cfoutput&gt;
&lt;/div&gt;

&lt;/div&gt;
</pre>
<p>Then some JavaScript. First, a function to call our chart.</p>
<pre class="brush: js">
if ( $j(&#039;.binding&#039;) != null ) {

$j.each($j(&#039;.binding&#039;),function(){
//console.log($j(this));
divid = $j(this).attr(&#039;id&#039;);
event = $j(this).attr(&#039;url&#039;);
//console.log(divid);
doBind({div:divid,url:event});
});

}
</pre>
<p>When the page has loaded, if there is any element with a class named &#8216;binding&#8217;, get some info (the div ID and the url to call), and call the function doBind:</p>
<pre class="brush: js">
function doBind(options) {
var $j = jQuery.noConflict();

//Some option (edit for your own)
var defaults = {
div: &#039;&#039;,
url: &#039;&#039;,
injectResult: &#039;&#039;
};
var options = $j.extend(defaults, options);

//Get the div that we want to update
var updatediv = $j(&#039;#&#039; + options.div);

//Show a loader on request
updatediv.html(&#039;&lt;div&gt;&lt;img src=&quot;ajax-loader.gif&quot;&gt;&lt;/div&gt;&#039;);

//The ajax request
$j.ajax({
type: &#039;GET&#039;,
url: options.url,
timeout: 2000, //You can edit that value to be able to extend the timeout time
success: function(data) {

//empty the container div
updatediv.html(&#039;&#039;);

//Hide the container
updatediv.css(&#039;visibility&#039;,&#039;hidden&#039;);

//Put the data
updatediv.html(data);

//Show the updated div
updatediv.css(&#039;visibility&#039;,&#039;visible&#039;);

},
//On error
error: function (XMLHttpRequest, textStatus, errorThrown) {
updatediv.html(&#039;Timeout contacting server.. &#039;+errorThrown);
}
});
}
</pre>
<p>The function send an ajax request to the url defined in the div, and update the content of the div. The function is well documented I think, but if you have any question, please drop me a comment. We finally need to put some event listener on our form so that at each change, we update the chart.</p>
<pre class="brush: js">
//Put an event listener on every select of the form
$j(&quot;select&quot;).change(function() {

//Get the selects values
var year = $j(&quot;#year option:selected&quot;).text();
var yearNumber = $j(&quot;#yearNumber option:selected&quot;).text();

//Create the url
url = &#039;chart.cfm&#039;;
if (year != &#039;&#039;) url = url +  &#039;?year=&#039; + year;
if (yearNumber != &#039;&#039; &amp;&amp; year != &#039;&#039;) {
url = url +  &#039;&amp;yearNumber=&#039; + yearNumber;
} else if(yearNumber != &#039;&#039; &amp;&amp; year == &#039;&#039;) {
url = url +  &#039;?yearNumber=&#039; + yearNumber;
}

//Call the doBind function and then the options
doBind({
div: &#039;chartholder&#039;,
url: url,

});

})
</pre>
<p>And there you have it! The final JS should look like this.</p>
<pre class="brush: js">
var $j = jQuery.noConflict();

$j(document).ready(function(){

//Put an event listener on every select of the form
$j(&quot;select&quot;).change(function() {

//Get the selects values
var year = $j(&quot;#year option:selected&quot;).text();
var yearNumber = $j(&quot;#yearNumber option:selected&quot;).text();

//Create the url
url = &#039;chart.cfm&#039;;
if (year != &#039;&#039;) url = url +  &#039;?year=&#039; + year;
if (yearNumber != &#039;&#039; &amp;&amp; year != &#039;&#039;) {
url = url +  &#039;&amp;yearNumber=&#039; + yearNumber;
} else if(yearNumber != &#039;&#039; &amp;&amp; year == &#039;&#039;) {
url = url +  &#039;?yearNumber=&#039; + yearNumber;
}

//Call the doBind function and then the options
doBind({
div: &#039;chartholder&#039;,
url: url,

});

})

if ( $j(&#039;.binding&#039;) != null ) {

$j.each($j(&#039;.binding&#039;),function(){
//console.log($j(this));
divid = $j(this).attr(&#039;id&#039;);
event = $j(this).attr(&#039;url&#039;);
//console.log(divid);
doBind({div:divid,url:event});
});

}

});

function updateChart() {

}

function doBind(options) {
var $j = jQuery.noConflict();

//Some option (edit for your own)
var defaults = {
div: &#039;&#039;,
url: &#039;&#039;,
injectResult: &#039;&#039;
};
var options = $j.extend(defaults, options);

//Get the div that we want to update
var updatediv = $j(&#039;#&#039; + options.div);

//Show a loader on request
updatediv.html(&#039;&amp;lt;div&amp;gt;&amp;lt;img src=&quot;ajax-loader.gif&quot;&amp;gt;&amp;lt;/div&amp;gt;&#039;);

//The ajax request
$j.ajax({
type: &#039;GET&#039;,
url: options.url,
timeout: 2000, //You can edit that value to be able to extend the timeout time
success: function(data) {

//empty the container div
updatediv.html(&#039;&#039;);

//Hide the container
updatediv.css(&#039;visibility&#039;,&#039;hidden&#039;);

//console.log(data);

//Put the data
updatediv.html(data);

//Show the updated div
updatediv.css(&#039;visibility&#039;,&#039;visible&#039;);

},
//On error
error: function (XMLHttpRequest, textStatus, errorThrown) {
updatediv.html(&#039;Timeout contacting server.. &#039;+errorThrown);
}
});
}
</pre>
<p>Here is the <a href="http://eremiya.net/wp-content/uploads/2010/06/jquery_flot_1.5_2.zip" target="_self">source code</a> if you want to try it by yourself. This method is a simple way to have a pod being updated by user input, using ajax. But what if I want to interact with the chart directly? I&#8217;ll be back&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://eremiya.net/2010/06/27/jquery-flot-tutorial-part-2/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Free Currency converter using Coldfusion, Google and Regex</title>
		<link>http://eremiya.net/2010/06/22/free-currency-converter-using-google-search-and-regex/</link>
		<comments>http://eremiya.net/2010/06/22/free-currency-converter-using-google-search-and-regex/#comments</comments>
		<pubDate>Mon, 21 Jun 2010 17:49:48 +0000</pubDate>
		<dc:creator>Jérémie</dc:creator>
				<category><![CDATA[Coldfusion]]></category>
		<category><![CDATA[Currency]]></category>
		<category><![CDATA[Google integration]]></category>
		<category><![CDATA[Regex]]></category>

		<guid isPermaLink="false">http://eremiya.net/?p=112</guid>
		<description><![CDATA[Here is an easy and free way to add a currency converter to you application.

First, let&#8217;s define some variables.

&#60;cfset from = &#039;EUR&#039;&#62;
&#60;cfset to = &#039;JPY&#039;&#62;
&#60;cfset amount = 1&#62;

Then, let&#8217;s get an HTTP request to Google search page.

&#60;cfhttp  url=&#34;http://www.google.co.jp/search?hl=en&#38;source=hp&#38;q=#arguments.amount##arguments.from#+in+#arguments.to#&#34;  useragent=&#34;MOZILLA&#34;  method=&#34;GET&#34; resolveurl=&#34;Yes&#34; throwOnError=&#34;Yes&#34;/&#62;

Pretty simple stuff so far. If you actually go to that url, you&#8217;ll see [...]]]></description>
			<content:encoded><![CDATA[<p>Here is an easy and free way to add a currency converter to you application.</p>
<p><span id="more-112"></span></p>
<p>First, let&#8217;s define some variables.</p>
<pre class="brush: coldfusion">
&lt;cfset from = &#039;EUR&#039;&gt;
&lt;cfset to = &#039;JPY&#039;&gt;
&lt;cfset amount = 1&gt;
</pre>
<p>Then, let&#8217;s get an HTTP request to Google search page.</p>
<pre class="brush: coldfusion">
&lt;cfhttp  url=&quot;http://www.google.co.jp/search?hl=en&amp;source=hp&amp;q=#arguments.amount##arguments.from#+in+#arguments.to#&quot;  useragent=&quot;MOZILLA&quot;  method=&quot;GET&quot; resolveurl=&quot;Yes&quot; throwOnError=&quot;Yes&quot;/&gt;
</pre>
<p>Pretty simple stuff so far. If you actually go to that url, you&#8217;ll see the result that we want in bold on the Google result page. That&#8217;s what we want. As ColdFusion stores the response in cfhttp.FileContent, let&#8217;s get that.</p>
<pre class="brush: coldfusion">
&lt;cfset c = cfhttp.FileContent&gt;
</pre>
<p>Now, let&#8217;s use regex to extract the data we want.</p>
<pre class="brush: coldfusion">
&lt;cfset  temp = REMatch(&#039;&lt;h2\b[^&gt;]*&gt;&lt;b&gt;.+?&lt;/b&gt;&lt;/h2&gt;&#039;,c)&gt;
&lt;cfset temp = temp[1]&gt;
</pre>
<p>REMatch will return an array. Studying the Dom of the Google page, there is only one h2 node with a class and a defined style (let&#8217;s hope it stays that way!!!).That will return something like this :</p>
<h2><strong><strong>1 Euro = 112.815605 Japanese  yen</strong></strong></h2>
<p>If you want to use that like it is, you are done. If you just need the value, add that:</p>
<pre class="brush: coldfusion">
&lt;cfset temp = listLast(temp,&#039;=&#039;)&gt;
</pre>
<p>This will select the part after the equal sign.</p>
<h2><strong><strong>112.815605 Japanese yen</strong></strong></h2>
<p>And the following expression will extract the part in front of the first space character.</p>
<pre class="brush: coldfusion">
&lt;cfset temp = listFirst(temp,&#039; &#039;)&gt;
</pre>
<p>And then you have it. Now you can format that number as you want.</p>
<h2><strong><strong><strong><strong>112.815605</strong></strong></strong></strong></h2>
<p>Hope that is useful to someone! <a title="Service cfc" href="http://eremiya.net/wp-content/uploads/2010/06/service.cfc.zip" target="_blank">Here is a cfc with that function</a>.</p>
<p>Note : This function is a hack and surely not ideal. The Google.com page changed and there is a pound sign now in the url which makes cfhttp request unstable. That is why I use google.co.jp for the moment. It will work if Google does not change the Dom of their result page&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://eremiya.net/2010/06/22/free-currency-converter-using-google-search-and-regex/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Jquery, Flot Tutorial (Part 1.5)</title>
		<link>http://eremiya.net/2009/10/16/jquery-flot-tutorial-part-1-5/</link>
		<comments>http://eremiya.net/2009/10/16/jquery-flot-tutorial-part-1-5/#comments</comments>
		<pubDate>Thu, 15 Oct 2009 16:37:35 +0000</pubDate>
		<dc:creator>Jérémie</dc:creator>
				<category><![CDATA[Coldfusion]]></category>
		<category><![CDATA[Jquery]]></category>
		<category><![CDATA[charting]]></category>
		<category><![CDATA[flot]]></category>

		<guid isPermaLink="false">http://eremiya.net/?p=47</guid>
		<description><![CDATA[Sorry for not posting more often. thanks for all the comments. I&#8217;ll work on the frequency of my posts!
Flot is indeed a great plugin. There is a lot of things that can be done using it.
Let&#8217;s say, I want to create a chart that represent the increase of a given year by month (from january [...]]]></description>
			<content:encoded><![CDATA[<p>Sorry for not posting more often. thanks for all the comments. I&#8217;ll work on the frequency of my posts!</p>
<p>Flot is indeed a great plugin. There is a lot of things that can be done using it.<br />
Let&#8217;s say, I want to create a chart that represent the increase of a given year by month (from january to december). There is several approach but I will use:</p>
<ul>
<li>cfc to get the data from the DB</li>
<li>custom axis renderer, for reasons I will explain later</li>
</ul>
<p><span id="more-47"></span><br />
Here is a preview of what we want to achieve.</p>
<p style="text-align: center;"><img class="aligncenter size-full wp-image-59" title="cfc driven flot charting" src="http://eremiya.net/wp-content/uploads/2009/10/Picture-11.png" alt="cfc driven flot charting" width="488" height="191" /></p>
<p>All the data are pulled from the database. For you all to try, I used a dsn that is from the default install of CF. And to make it more &#8220;sexy&#8221;, we&#8217;ll add a zest of ajax!<br />
Let&#8217;s get started. First, the cfc. Of course you can get the data with whatever server technology you are using.<br />
We are using the cfartgallery datasourse. In that datasource, you have a table name APP.ORDERS. Basically, in this table, there is the orders for the art gallery application. What we want to do is to call a function that will return a query with the monthly order amount for a special year.</p>
<pre class="brush: coldfusion">&lt;cffunction name=&quot;getByDate&quot; output=&quot;false&quot; access=&quot;public&quot; returntype=&quot;query&quot;&gt;
&lt;cfargument name=&quot;year&quot; type=&quot;Numeric&quot; required=&quot;false&quot;&gt;

&lt;cfset nq = QueryNew(&quot;orderdate, total&quot;, &quot;VarChar, Integer&quot;)&gt;

&lt;cfloop from=&quot;1&quot; to=&quot;12&quot; index=&quot;i&quot;&gt;

&lt;cfquery name=&quot;q&quot; datasource=&quot;cfartgallery&quot;&gt;
SELECT Year(ORDERDATE) AS ORDERYEAR, TOTAL
FROM APP.ORDERS
WHERE Month(ORDERDATE) = #i#
AND Year(ORDERDATE) = #year#
&lt;/cfquery&gt;

&lt;cfset temp = QueryAddRow(nq)&gt;
&lt;cfset Temp = QuerySetCell(nq, &quot;orderdate&quot;, year &amp; &#039;/0&#039; &amp; i)&gt;
&lt;cfset Temp = QuerySetCell(nq, &quot;total&quot;, Val(q.total))&gt;

&lt;/cfloop&gt;

&lt;cfreturn nq&gt;
&lt;/cffunction&gt;</pre>
<p>In this quite simple function, we ccreate a new query named nq then loop for 1 to 12 (which are months of the year, from january to december) the we query the database for each one of those months then we append the new query nq with the total and the date with the format &#8220;YYYY/M&#8221; (no leading 0). Notice that the only argument we are passing to that function is the year. We&#8217;ll come to that later. Notice also that the data type for the orderdate is VarChar. We don&#8217;t want to receive a date from the cfc, because it might cause some problems later.</p>
<p>Now, we are going to add a new function to our cfc that we are going to call from our cfm page.</p>
<pre class="brush: coldfusion">&lt;cffunction name=&quot;getStructForChart&quot; output=&quot;false&quot; access=&quot;remote&quot; returntype=&quot;any&quot;&gt;

&lt;cfargument name=&quot;year&quot; type=&quot;Numeric&quot; required=&quot;false&quot; default=&quot;2004&quot;&gt;
&lt;cfargument name=&quot;yearNumber&quot; type=&quot;Numeric&quot; required=&quot;false&quot; hint=&quot;Number of preceding years&quot;&gt;

&lt;cfset myStruct = arraynew(1)&gt;

&lt;cfset data = getByDate(arguments.year)&gt;
&lt;cfset ArrayAppend(myStruct,data)&gt;

&lt;cfif arguments.yearNumber gt 0&gt;
&lt;cfset arguments.yearNumber = arguments.yearNumber - 1&gt;
&lt;cfloop from=&quot;1&quot; to=&quot;#arguments.yearNumber#&quot; index=&quot;y&quot;&gt;
&lt;cfset data = getByDate(arguments.year-y)&gt;
&lt;cfset ArrayAppend(myStruct,data)&gt;
&lt;/cfloop&gt;
&lt;/cfif&gt;

&lt;cfreturn myStruct&gt;

&lt;/cffunction&gt;</pre>
<p>In this function, we retrieve the year argument and this time, it has a default value. Because of the data in the table, we set it 2004, but of course in your application, you can set it to whatever is fine, for exaple #Year(Now())# for the current year. We also introduce a new argument &#8220;yearNumber&#8221; which is the number of preeceding year we want to display.</p>
<p>Here we create an array that will be transform to json when we call the cfc using jquery. In this array, we will put the query returned from the getByDate function. If the yearNumber argument is greater than 0, we loop from 1 to the argument yearNumber and we call the function again by passing a new value for the year argument. Finally, we will append the returned query to the array. That&#8217;s it for the cfc.</p>
<p>Now, let&#8217;s create the javascript function.</p>
<pre class="brush: js">var $j = jQuery.noConflict();

$j(document).ready(function(){

//getData();
drawChart();

});</pre>
<p>Just to remind you, as I use different javascript libraries, I defined var $j = jQuery.noConflict(); to avoid conflict.</p>
<p>In my <a href="http://www.eremiya.net/?p=7" target="_blank">previous blog</a>, I specified an array that will be the data store. Let&#8217;s define it again.</p>
<pre class="brush: js">
var dataObject = [];
var plotarea = $j(&quot;#placeholder&quot;);
</pre>
<p>Now let&#8217;s defined too important variables and a handy array that we will use for our custom axis rendering:</p>
<pre class="brush: js">
var &lt;cfoutput&gt;#toScript(url.year, &quot;year&quot;)#&lt;/cfoutput&gt;
var &lt;cfoutput&gt;#toScript(url.yearNumber, &quot;yearNumber&quot;)#&lt;/cfoutput&gt;

var months = [&#039;jan&#039;, &#039;feb&#039;, &#039;mars&#039;, &#039;apr&#039;, &#039;may&#039;, &#039;jun&#039;, &#039;jul&#039;, &#039;aug&#039;, &#039;sep&#039;, &#039;oct&#039;, &#039;nov&#039;, &#039;dec&#039;];
</pre>
<p>The months array is basically an array of strings, but you could put variables if for example your site is multilingual and using a resource bundle. the too variables get the url var of the year and the yearNumber and pass them to the following ajax call to the cfc:</p>
<pre class="brush: js">
$j.getJSON(
&#039;http://192.168.0.100:81/model/cfc/service/charting.cfc?wsdl&#039;,
{ method : &#039;getStructForChart&#039;, returnformat : &#039;json&#039;, queryformat : &#039;column&#039;, year : year, yearNumber : yearNumber },
function(data) {
</pre>
<p>A great thing with cfc is that you can call it directly and specify that you want a Json result!!! That is a great gain of time!! You can change the url of your cfc but do not forget the  ?wsdl at the end. That makes the magic! Once we receive the response, let&#8217;s populate the dataObject array.</p>
<pre class="brush: js">
for (var a=0; a&lt;data.length; a++) {

eval(&quot;data&quot; + a + &quot; = []&quot;);

for (var i=0; i&lt;data[a].ROWCOUNT; i++) {

var myDate = new Date(data[a].DATA.orderdate[i]+&#039;/01&#039;);
eval(&quot;data&quot; + a).push([myDate.getMonth(),data[a].DATA.total[i]]);
var dataYear = myDate.getFullYear();

}

dataObject.push({label:dataYear,data:eval(&quot;data&quot; + a)})

}
</pre>
<p>Here, we loop through the response (which is an array of objects) and we create a dynamic array (eval(&#8220;data&#8221; + a + &#8221; = []&#8220;);) to push our formated data in. then we push the month of our newly formated date (formated for js using the new Date() function) and the according order amount. And finally we push that dynamic array to our dataObject array. Now the rest is just formating.</p>
<pre class="brush: js">
var options = {
legend: {
show: true,
margin: 10,
backgroundOpacity: 0.5
},
points: {
show: true,
radius: 6
},
lines: {
show: true
},
grid: {
borderWidth:0,
labelMargin:15,
clickable:true,
hoverable:true,
autoHighlight:true
},
xaxis: {
tickSize: 1,
tickFormatter: function(val,axis) {
return months[val];
}
}
};
</pre>
<p>There is some changes from my <a href="http://www.eremiya.net/?p=7" target="_blank">previous post</a>, the radius of the point to make them bigger, no formatting on the vertical axis (yaxis), the points are clickable now, and I have a custom renderer on my horizontal axis (xaxis). That function return the month name defined in the months array for a given value. We&#8217;re almost done. Let&#8217;s draw the chart and add a function to handle the click on a point:</p>
<pre class="brush: js">
$j.plot(plotarea, dataObject, options);

$j(&quot;#placeholder&quot;).bind(&quot;plotclick&quot;, function (event, pos, item) {
alert(&#039;In &#039;+item.series.label+&#039;/&#039;+item.datapoint[0]+&#039;, the order amout is &#039;+item.datapoint[1]);
});</pre>
<p>In that function, when a button is clicked, three variables are passed to the function. the item variable is, as its name tells, the item values (the horizontal and vertical data).  The item.series.label return the label (here the year of the series). Here is the final code:</p>
<pre class="brush: coldfusion">&amp;lt;cfparam name=&quot;url.year&quot; type=&quot;numeric&quot; default=&quot;2004&quot;&amp;gt;
&amp;lt;cfparam name=&quot;url.yearNumber&quot; type=&quot;numeric&quot; default=&quot;0&quot;&amp;gt;
&amp;lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Strict//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd&quot;&amp;gt;
&amp;lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&amp;gt;
&amp;lt;head&amp;gt;
&amp;lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=UTF-8&quot; /&amp;gt;

&amp;lt;title&amp;gt;CFC Driven Chart&amp;lt;/title&amp;gt;
&amp;lt;meta name=&quot;description&quot; content=&quot;eremiya&quot; /&amp;gt;

&amp;lt;script language=&quot;javascript&quot; type=&quot;text/javascript&quot; src=&quot;jquery/jquery-1.3.2.js&quot;&amp;gt;&amp;lt;/script&amp;gt;
&amp;lt;script language=&quot;javascript&quot; type=&quot;text/javascript&quot; src=&quot;js/jquery/flot/jquery.flot.js&quot;&amp;gt;&amp;lt;/script&amp;gt;

&amp;lt;/head&amp;gt;
&amp;lt;body&amp;gt;

&amp;lt;div id=&quot;placeholder&quot; style=&quot;width:800px;height:300px&quot;&amp;gt;&amp;lt;/div&amp;gt;

&amp;lt;script id=&quot;source&quot; language=&quot;javascript&quot; type=&quot;text/javascript&quot;&amp;gt;

var $j = jQuery.noConflict();

$j(document).ready(function(){

//getData();
drawChart();

});

function drawChart() {

var dataObject = [];
var plotarea = $j(&quot;#placeholder&quot;);

var &lt;cfoutput&gt;#toScript(url.year, &quot;year&quot;)#&lt;/cfoutput&gt;
var &lt;cfoutput&gt;#toScript(url.yearNumber, &quot;yearNumber&quot;)#&lt;/cfoutput&gt;

var months = [&#039;jan&#039;, &#039;feb&#039;, &#039;mars&#039;, &#039;apr&#039;, &#039;may&#039;, &#039;jun&#039;, &#039;jul&#039;, &#039;aug&#039;, &#039;sep&#039;, &#039;oct&#039;, &#039;nov&#039;, &#039;dec&#039;];

$j.getJSON(
&#039;http://192.168.0.100:81/model/cfc/service/charting.cfc?wsdl&#039;,
{ method : &#039;getStructForChart&#039;, returnformat : &#039;json&#039;, queryformat : &#039;column&#039;, year : year, yearNumber : yearNumber },
function(data) {
for (var a=0; a&lt;data.length; a++) {

eval(&quot;data&quot; + a + &quot; = []&quot;);

for (var i=0; i&lt;data[a].ROWCOUNT; i++) {

var myDate = new Date(data[a].DATA.orderdate[i]+&#039;/01&#039;);
eval(&quot;data&quot; + a).push([myDate.getMonth(),data[a].DATA.total[i]]);
var dataYear = myDate.getFullYear();

}

dataObject.push({label:dataYear,data:eval(&quot;data&quot; + a)})

}

var options = {
legend: {
show: true,
margin: 10,
backgroundOpacity: 0.5
},
points: {
show: true,
radius: 6
},
lines: {
show: true
},
grid: {
borderWidth:0,
labelMargin:15,
clickable:true,
hoverable:true,
autoHighlight:true
},
xaxis: {
tickSize: 1,
tickFormatter: function(val,axis) {
return months[val];
}
}
};

$j.plot(plotarea, dataObject, options);

$j(&quot;#placeholder&quot;).bind(&quot;plotclick&quot;, function (event, pos, item) {
alert(&#039;In &#039;+item.series.label+&#039;/&#039;+item.datapoint[0]+&#039;, the order amout is &#039;+item.datapoint[1]);
});
}
);

}
&amp;lt;/script&amp;gt;

&amp;lt;/body&amp;gt;

&amp;lt;/html&amp;gt;</pre>
<p>Quite a long post, sorry about that! Please tell me what you think about it! And <a href="http://eremiya.net/wp-content/uploads/2009/10/jquery_flot_1.5.zip">here are the download files</a>!<br />
Hey, but what if we want to change the number of year using ajax?&#8230; &#8220;I&#8217;ll be back&#8230; sooner&#8221;</p>
]]></content:encoded>
			<wfw:commentRss>http://eremiya.net/2009/10/16/jquery-flot-tutorial-part-1-5/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Hello world! (eremiya version)</title>
		<link>http://eremiya.net/2009/07/04/hello-world/</link>
		<comments>http://eremiya.net/2009/07/04/hello-world/#comments</comments>
		<pubDate>Sat, 04 Jul 2009 03:29:57 +0000</pubDate>
		<dc:creator>Jérémie</dc:creator>
				<category><![CDATA[Coldfusion]]></category>
		<category><![CDATA[MVC]]></category>
		<category><![CDATA[Model-Glue]]></category>

		<guid isPermaLink="false">http://eremiya.net/?p=1</guid>
		<description><![CDATA[Hi and welcome to my blog. I am new to the blogging community but I&#8217;ve been there for years, hiding among you guys! I decided to create that blog for many reasons, but mainly to :

make tutorials for newbies like me,
blog about Coldfusion, Model-Glue and MVC dev as well as ORM dev
RIA dev (Flex, Air, [...]]]></description>
			<content:encoded><![CDATA[<p>Hi and welcome to my blog. I am new to the blogging community but I&#8217;ve been there for years, hiding among you guys! I decided to create that blog for many reasons, but mainly to :</p>
<ul>
<li>make tutorials for newbies like me,</li>
<li>blog about Coldfusion, Model-Glue and MVC dev as well as ORM dev</li>
<li>RIA dev (Flex, Air, &#8230;)</li>
<li>release some open source projects I&#8217;ve been working on<span id="more-1"></span></li>
</ul>
<p>Let me introduce myself in a few word. I am French and I work as IT manager at the French Chamber of Commerce and Industry in Japan (<a title="CCIFJ" href="http://www.ccifj.or.jp" target="_blank">CCIFJ</a>). So obviously, I work in Japan&#8230; I have been using Coldfusion for years now. I am fortunate enough to use CF at work and develop projects on that platform. CCIFJ is a leading French Chamber in the world and the second biggest in Japan after the American Chamber, which means there is a constant need for straight forward development to meet the expectations of the members. I give my best try to meet them!</p>
<p>I hope you&#8217;ll find this blog usefull. Do not hesitate to drop a comment, to edit my work to make it better, or to correct me if I am wrong. After all, I am a newbie.</p>
<p>So to start, <em>what if </em>I want to build an online store, using Model-glue (MG)&#8230; &#8220;I&#8217;ll be back!&#8221;</p>
]]></content:encoded>
			<wfw:commentRss>http://eremiya.net/2009/07/04/hello-world/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
