<?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; charting</title>
	<atom:link href="http://eremiya.net/category/charting/feed/" rel="self" type="application/rss+xml" />
	<link>http://eremiya.net</link>
	<description>Just another WordPress weblog</description>
	<lastBuildDate>Thu, 04 Nov 2010 22:52:20 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.5</generator>
		<item>
		<title>Jquery, HighCharts, and Coldfusion tutorial (Part 0 &#8211; the data)</title>
		<link>http://eremiya.net/2010/11/02/jquery-highcharts-and-coldfusion-tutorial-part-0-the-data/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=jquery-highcharts-and-coldfusion-tutorial-part-0-the-data</link>
		<comments>http://eremiya.net/2010/11/02/jquery-highcharts-and-coldfusion-tutorial-part-0-the-data/#comments</comments>
		<pubDate>Tue, 02 Nov 2010 08:10:21 +0000</pubDate>
		<dc:creator>Jérémie</dc:creator>
				<category><![CDATA[HighCharts]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Jquery]]></category>
		<category><![CDATA[charting]]></category>

		<guid isPermaLink="false">http://eremiya.net/?p=177</guid>
		<description><![CDATA[In my previous post, I talked about the various options allowed by the HighCharts library to draw a chart. Now let&#8217;s talk about data! Things are beginning to be interesting! There are 2 things we must know when we want to use a charting library to represent our data: Our own data (knowing our data [...]]]></description>
			<content:encoded><![CDATA[<p>In my <a href="http://eremiya.net/2010/11/02/jquery-highcharts-and-coldfusion-to-the-rescue-part-1/" target="_self">previous post</a>, I talked about the various options allowed by the HighCharts library to draw a chart. Now let&#8217;s talk about data! Things are beginning to be interesting!</p>
<p><span id="more-177"></span>There are 2 things we must know when we want to use a charting library to represent our data:</p>
<ol>
<li>Our own data (knowing our data well will help us to format it without being a pain in the &#8230; head! You&#8217;ll understand what I mean in following posts)</li>
<li>The format accepted by the library we are going to use</li>
</ol>
<p>Once we know that, we have nothing to fear! For that post, we will create the data, so wedon&#8217;t have to worry about knowing our data. Let&#8217;s Examine the format of the series array that we should pass to our drawChart function. Here is a simple representation (I hope) of the series format.</p>
<p><a href="http://eremiya.net/wp-content/uploads/2010/11/data.png"><img class="aligncenter size-full wp-image-178" title="series data format" src="http://eremiya.net/wp-content/uploads/2010/11/data.png" alt="" width="560" height="300" /><br />
</a>Series is an <a href="http://www.w3schools.com/js/js_obj_array.asp">JavaScript array</a> of objects (or structures) containing 2 elements : the name of the series (a string) and the data (an array). <a href="http://msdn.microsoft.com/en-us/library/bb299886.aspx" target="_blank">Here is an article form the evil empire</a> explaining JavaScript Object Notation. So, let&#8217;s format create an array of objects to send it to our drawChart function.</p>
<pre class="brush: javascript">
var $j = jQuery.noConflict();
var chart1; // globally available

$j(document).ready(function() {
//Put the logic here
});
</pre>
<p>The best place to put the code formatting the data (and next the ajax call) is in the onDomReady function. It will be called once the page has loaded. But of course, you can place it where ever is fine with you.</p>
<pre class="brush: javascript">
var series1 = [];
var series2 = [];
var series3 = [];
var categories = [];
</pre>
<p>Then let&#8217;s define our series arrays (the data array of each object) and the categories array.</p>
<pre class="brush: javascript">
for(i=1;i&lt;13;i++) {
//Populate the data with random values
series1.push(Math.round(Math.random()*100));
series2.push(Math.round(Math.random()*100));
series3.push(Math.round(Math.random()*100));
//Create the categories object
categories.push(2000+i);
}
</pre>
<p>So, to populate our arrays, we will create random numbers (between 0 &amp; 1), multiply that number by 100 and round the result to the nearest integer (for <a href="http://www.w3schools.com/js/js_obj_math.asp" target="_blank">information on math functions</a> of JavaScript). We then push (I love that word!) the number in the array. And we do it for the 3 arrays. As we want to represent 12 years of tea production, we loop from 1 to 12, and create the years that we push to the categories array.</p>
<p>So now we are almost done. We just need to put those arrays in objects and push those objects in our main array. Nothing dificult:</p>
<pre class="brush: javascript">
var series = [
{
name:&#039;France&#039;,
data: series1
},
{
name:&#039;USA&#039;,
data: series2
},
{
name:&#039;Japan&#039;,
data: series3
}
]
</pre>
<p>And here it is. Now we can call the drawChart function and pass the 2 arguments, series and categories. And this is the result :</p>
<p><a href="http://eremiya.net/wp-content/uploads/2010/11/hc.png"><img class="aligncenter size-full wp-image-180" title="tea production" src="http://eremiya.net/wp-content/uploads/2010/11/hc.png" alt="" width="560" height="220" /></a>So you can see that our chart just look as we wanted, based on the options we set. Here is the <a href="http://eremiya.net/wp-content/uploads/2010/11/highcharts_sample01.zip">source code</a> for those who wants to try. Play with the chart, I have no doubt you&#8217;ll find it powerful. But what if we want to pull the data from the database using cfc and Json? &#8220;I&#8217;ll be back&#8221;</p>
]]></content:encoded>
			<wfw:commentRss>http://eremiya.net/2010/11/02/jquery-highcharts-and-coldfusion-tutorial-part-0-the-data/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Jquery, HighCharts, and Coldfusion tutorial (Part 1)</title>
		<link>http://eremiya.net/2010/11/02/jquery-highcharts-and-coldfusion-tutorial-part-1/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=jquery-highcharts-and-coldfusion-tutorial-part-1</link>
		<comments>http://eremiya.net/2010/11/02/jquery-highcharts-and-coldfusion-tutorial-part-1/#comments</comments>
		<pubDate>Tue, 02 Nov 2010 06:37:18 +0000</pubDate>
		<dc:creator>Jérémie</dc:creator>
				<category><![CDATA[HighCharts]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Jquery]]></category>
		<category><![CDATA[charting]]></category>

		<guid isPermaLink="false">http://eremiya.net/?p=167</guid>
		<description><![CDATA[Flot is great. But, lately I discovered the HighCharts library and frankly speaking, it is blowing my mind. So, let&#8217;s chart again! Let&#8217;s try to adapt the examples of my previous posts  to the HighCharts and see what that awesome library can bring on! On our newly created cfm page (or anything else for the [...]]]></description>
			<content:encoded><![CDATA[<p>Flot is great. But, lately I discovered the <a href="http://www.highcharts.com" target="_blank">HighCharts</a> library and frankly speaking, it is blowing my mind. So, let&#8217;s chart again! Let&#8217;s try to adapt the examples of my previous posts  to the HighCharts and see what that awesome library can bring on!</p>
<p><span id="more-167"></span>On our newly created cfm page (or anything else for the others), let&#8217;s first put the chart container</p>
<pre class="brush: html">
&lt;div id=&quot;chart&quot; style=&quot;width: 100%; height: 400px&quot;&gt;
&lt;div id=&quot;loading&quot;&gt;
&lt;img src=&quot;/assets/images/loader.gif&quot;&gt;
&lt;/div&gt;
&lt;/div&gt;
</pre>
<p>Nothing too fancy here. I just put a loading image, not really handy now, but its time of glory will come in following posts. Now some javascript.</p>
<pre class="brush: javascript">
function drawChart(series,categories) {

chart1 = new Highcharts.Chart({
//Options for the chart goes here
});

}
</pre>
<p>The drawChart function takes 2 arguments: the series (the data) and the categories (the x axis values). This will give us some room to make an ajax call, process the data and then call the function, passing those 2 arguments. For now let&#8217;s concentrate on the options. The first one, <span style="color: #800000;"><strong>chart </strong></span>(options name are in <span style="color: #800000;"><strong>red</strong></span>, parameters in <span style="color: #008080;"><strong>green</strong></span>).</p>
<pre class="brush: javascript">
chart: {
renderTo: &#039;chart&#039;,
defaultSeriesType: &#039;line&#039;,
zoomType: &#039;x&#039;
}
</pre>
<p>In <span style="color: #800000;"><strong>chart</strong></span>, the <strong><span style="color: #008080;">renderTo</span></strong> parameter name says it all, where do we want to render the chart. So you need to put the id of the container. <span style="color: #008080;"><strong>defaultSeriesType</strong></span> is the type of chart we want to create (for a complete gallery of series type, have a look at the <a href="http://www.highcharts.com/demo/" target="_blank">online gallery of HighCharts</a>). We also want to enable zoom on the chart. just one line, and Boom! (© S. Job)</p>
<pre class="brush: javascript">
credits: {
enabled: false
},
title: {
text: &#039;Tea production&#039;
}
</pre>
<p>If we want to get rid of the <span style="color: #800000;"><strong>credits</strong></span> (enabled by default), we can set <span style="color: #008080;"><strong>enabled</strong></span> to false. We can also set a <strong><span style="color: #800000;">title</span></strong> to our chart. If we don&#8217;t want one, we have to set <span style="color: #008080;"><strong>text</strong></span> to &#8220;&#8221; or null. Let&#8217;s put a dummy value.</p>
<pre class="brush: javascript">
yAxis: {
min: 0,
title: {
text: &#039;Tea production comparison&#039;
}
}
</pre>
<p>The <span style="color: #800000;"><strong>yAxis</strong></span> is quite fun to set. First, if <span style="color: #008080;"><strong>min</strong></span> is set to 0, the y axis is going to begin by 0, if you ignore it, the value is calculated automatically. We can go quite deep in the customization of that option. We can also set a <span style="color: #008080;"><strong>title</strong></span> to the y axis (quite useful when you have a double axis chart). Once again, let&#8217;s put a dummy one.</p>
<pre class="brush: javascript">
xAxis: {
categories: categories
}
</pre>
<p>The <span style="color: #800000;"><strong>xAxis</strong></span> now. And here is our <span style="color: #008080;"><strong>categories</strong></span> argument. This is going to be the values of our x axis. One important thing, you can set a <strong><span style="color: #008080;">type</span></strong> to the <span style="color: #800000;"><strong>xAxis</strong></span> (as for the <span style="color: #800000;"><strong>yAxis</strong></span>) : either &#8220;linear&#8221; or &#8220;datetime&#8221;. If we choose datetime, we should pass a number in milliseconds and a <strong><span style="color: #008080;">pointStart</span></strong> parameter of type date, like Date.UTC(2010, 11, 02). The axis is going to be created automatically for us. Very useful for a chart showing the evolution of a currency every 10 mn for example. For our chart, let&#8217;s keep the linear type (default by the way).</p>
<pre class="brush: javascript">
legend: {
style: {
left: &#039;auto&#039;,
bottom: &#039;auto&#039;,
right: &#039;70px&#039;,
top: &#039;35px&#039;
}
}
</pre>
<p>Next, the <strong><span style="color: #800000;">legend</span></strong>. We can modify our legend and place it exactly where we want, thanks to css. So, using the <span style="color: #008080;"><strong>style</strong></span> parameter, let&#8217;s put our legend to the top right corner of our chart.</p>
<pre class="brush: javascript">
tooltip: {
formatter: function() {
return &#039;&lt;span style=&quot;font-size:0.9em;color:#666666;&quot;&gt;&#039;+ this.series.name +&#039;&lt;/span&gt;&lt;br/&gt;&lt;p style=&quot;color:&#039; + this.series.color + &#039;&quot;&gt;&#039; + this.y + &#039; tons of tea in &#039; + this.x + &#039;&lt;/p&gt;&#039;;
},
style: {
}
}
</pre>
<p>We want to format our <span style="color: #800000;"><strong>tooltip</strong></span> to show the name of the the serie, the volume of tea producted for a given year. And as you see, it is quite simple to do using the <span style="color: #008080;"><strong>formatter</strong></span> function and html.The variable this (and this.series) worths a deeper look into. Don&#8217;t hesitate to use console.log() to find out what they can offer.</p>
<pre class="brush: javascript">
symbols: [&quot;circle&quot;,&quot;circle&quot;,&quot;circle&quot;],
series: series
</pre>
<p>We can also set the <span style="color: #800000;"><strong>symbols</strong></span> of each data series (the appearance of the data points). Here we chose circle, but you have the choice between &#8216;circle&#8217;, &#8216;diamond&#8217;, &#8216;square&#8217;, &#8216;triangle&#8217; or even &#8216;triangle-down&#8217;. We pass an array of symbols, for each series. It is not a problem to have more symbols in the array than the number of series objects. If we have less than the series, the symbol will be chosen automatically. Finally, the <strong><span style="color: #800000;">series</span></strong>. And here is our second arguments.</p>
<p>As you see, there is quite a deep level of customization possible with HighCharts. We could set the colors (passing an array of colors as an option) or export the chart in several format (we&#8217;ll be back on that subject!).Again, you can find everything about the <a href="http://www.highcharts.com/ref/" target="_blank">api on the HighCharts site</a>.</p>
<p>That post turned to be quite long. But here you have the basic explanation of drawing a chart with HighCharts. But how do we get the data? &#8220;I&#8217;ll be back!&#8221;</p>
]]></content:encoded>
			<wfw:commentRss>http://eremiya.net/2010/11/02/jquery-highcharts-and-coldfusion-tutorial-part-1/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Jquery, Flot Tutorial (Part 2 revisited)</title>
		<link>http://eremiya.net/2010/06/30/jquery-flot-tutorial-part-2-revisited/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=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/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=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>Jquery, Flot Tutorial (Part 1.5)</title>
		<link>http://eremiya.net/2009/10/16/jquery-flot-tutorial-part-1-5/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=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 [...]]]></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>Jquery, Flot Tutorial (Part 1)</title>
		<link>http://eremiya.net/2009/07/08/jquery-flot-tutorial-part-1/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=jquery-flot-tutorial-part-1</link>
		<comments>http://eremiya.net/2009/07/08/jquery-flot-tutorial-part-1/#comments</comments>
		<pubDate>Wed, 08 Jul 2009 10:13:35 +0000</pubDate>
		<dc:creator>Jérémie</dc:creator>
				<category><![CDATA[Jquery]]></category>
		<category><![CDATA[charting]]></category>
		<category><![CDATA[flot]]></category>

		<guid isPermaLink="false">http://eremiya.net/?p=7</guid>
		<description><![CDATA[Flot is a great plugin for JQuery! I decided to make a simple tutorial in this part and then try to have something more complex (ajax request pulling out data from the database).  Let&#8217;s make things first: let&#8217;s invoke the scripts. &#60;script src=&#34;../jquery/jquery-1.3.2.js&#34; type=&#34;text/javascript&#34;&#62;&#60;/script&#62; &#60;script src=&#34;../js/jquery/flot/jquery.flot.js&#34; type=&#34;text/javascript&#34;&#62;&#60;/script&#62; &#60;!--[if IE]&#62;&#60;script language=&#34;javascript&#34; type=&#34;text/javascript&#34; src=&#34;../excanvas.pack.js&#34;&#62;&#60;/script&#62;&#60;![endif]--&#62; Then, let&#8217;s place [...]]]></description>
			<content:encoded><![CDATA[<p><a title="Flot" href="http://code.google.com/p/flot/" target="_blank">Flot</a> is a great plugin for JQuery! I decided to make a simple tutorial in this part and then try to have something more complex (ajax request pulling out data from the database). <span id="more-7"></span></p>
<p>Let&#8217;s make things first: let&#8217;s invoke the scripts.</p>
<pre class="brush: js">&lt;script src=&quot;../jquery/jquery-1.3.2.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;
&lt;script src=&quot;../js/jquery/flot/jquery.flot.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;
&lt;!--[if IE]&gt;&lt;script language=&quot;javascript&quot; type=&quot;text/javascript&quot; src=&quot;../excanvas.pack.js&quot;&gt;&lt;/script&gt;&lt;![endif]--&gt;</pre>
<p>Then, let&#8217;s place a div that will contain the chart.</p>
<pre class="brush: html">&lt;div id=&quot;placeholder&quot; style=&quot;width:600px;height:300px&quot;&gt;&lt;/div&gt;</pre>
<p>Now, let&#8217;s put our script to initialize the chart:</p>
<pre class="brush: js">&lt;script language=&quot;javascript&quot; type=&quot;text/javascript&quot;&gt;

var $j = jQuery.noConflict();

$j(function () {

var dataArray = [];

for (var i=1; i&lt;13; i++) {
dataArray.push([2000+i,Math.random()*11]);
}

//console.log(dataArray);

var data = [
{
label: &quot;Yearly increase&quot;,
data: dataArray
}
];

var options = {
legend: {
show: true,
margin: 10,
backgroundOpacity: 0.5
},
points: {
show: true,
radius: 3
},
lines: {
show: true
},
grid: {
borderWidth:0
},
xaxis: {
tickSize:1
},
yaxis: {
tickSize:1,
tickDecimals: 0
}
};

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

$j.plot( plotarea , data, options );
});
&lt;/script&gt;</pre>
<p>Let me explain: as I am using other js libraries, I did put the first line to avoid conflict</p>
<pre class="brush: js">var $j = jQuery.noConflict();</pre>
<p>then i specified an array that will be my data store. Math.random()*11 will generate a number randomly between 0 and 10.</p>
<pre class="brush: js">

var dataArray = [];

for (var i=1; i&lt;13; i++) {
dataArray.push([2000+i,Math.random()*11]);
}
</pre>
<p>As I would like to have a label on my chart, I can specify that in the data format and pass my dataArray (If I have multiple dataset, that is there I should set them)</p>
<pre class="brush: js">

var data = [
{
label: &quot;Yearly increase&quot;,
data: dataArray
}
];
</pre>
<p>And I set the options for my grid, x and y axes, the legend and so on&#8230;</p>
<pre class="brush: js">

var options = {
legend: {
show: true,
margin: 10,
backgroundOpacity: 0.5
},
points: {
show: true,
radius: 3
},
lines: {
show: true
},
grid: {
borderWidth:0
},
xaxis: {
tickSize:1
},
yaxis: {
tickSize:1,
tickDecimals: 0
}
};
</pre>
<p>in more details:</p>
<ul>
<li><span style="color: #800000;">legend</span> will let you customize the &#8230; legend</li>
<li><span style="color: #800000;">points</span> &amp; <span style="color: #800000;">lines</span> are the type I chose for my series (you could choose bars or the newly pie type)</li>
<li>the <span style="color: #800000;">grid</span> is the background of your chart</li>
<li><span style="color: #800000;">xaxis</span> is the &#8220;horizontal&#8221; line and the <span style="color: #800000;">yaxis</span>, the &#8230; vertical one (you&#8217;re maybe not that newbie, sorry!)</li>
</ul>
<p>for more details, you can check the <a title="API text" href="http://people.iola.dk/olau/flot/API.txt" target="_blank">api text document</a>.</p>
<p>Finally get the placeholder and call flot to draw the chart by passing the variables to the plot function:</p>
<pre class="brush: js">

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

$j.plot( plotarea , data, options );
</pre>
<p>Here is the final code:</p>
<pre class="brush: xml">&amp;lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.01 Transitional//EN&quot; &quot;http://www.w3.org/TR/html4/loose.dtd&quot;&amp;gt;
&lt;html&gt;
&lt;head&gt; &lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=utf-8&quot;&gt; &lt;title&gt;Flot Examples&lt;/title&gt; &lt;link href=&quot;layout.css&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot;&gt;&lt;/link&gt; &lt;!--[if IE]&gt;&lt;script language=&quot;javascript&quot; type=&quot;text/javascript&quot; src=&quot;../excanvas.pack.js&quot;&gt;&lt;/script&gt;&lt;![endif]--&gt; &lt;script language=&quot;javascript&quot; type=&quot;text/javascript&quot; src=&quot;../jquery/jquery-1.3.2.js&quot;&gt;&lt;/script&gt; &lt;script language=&quot;javascript&quot; type=&quot;text/javascript&quot; src=&quot;../js/jquery/flot/jquery.flot.js&quot;&gt;&lt;/script&gt; &lt;/head&gt;
&lt;body&gt; &lt;h2&gt;Chart&lt;/h2&gt;
&lt;div id=&quot;placeholder&quot; style=&quot;width:600px;height:300px&quot;&gt;&lt;/div&gt;
&lt;script language=&quot;javascript&quot; type=&quot;text/javascript&quot;&gt;

var $j = jQuery.noConflict();

$j(function () {

var dataArray = [];

for (var i=1; i&lt;13; i++) {
dataArray.push([2000+i,Math.random()*11]);
}

//console.log(dataArray);

var data = [
{
label: &quot;Yearly increase&quot;,
data: dataArray
}
];

var options = {
legend: {
show: true,
margin: 10,
backgroundOpacity: 0.5
},
points: {
show: true,
radius: 3
},
lines: {
show: true
},
grid: {
borderWidth:0
},
xaxis: {
tickSize:1
},
yaxis: {
tickSize:1,
tickDecimals: 0
}
};

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

$j.plot( plotarea , data, options );
});
&lt;/script&gt;

&lt;/body&gt;
&lt;/html&gt;
</pre>
<p>And here is the final result in your browser:</p>
<p style="text-align: center;"><img class="size-full wp-image-36 aligncenter" title="chart" src="http://eremiya.net/wp-content/uploads/2009/07/chart.png" alt="line chart using jquery flot" width="563" height="319" /></p>
<p style="text-align: left;">What if now, we want to pull the data from the database using cf&#8230; &#8220;I&#8217;ll be back&#8221;!</p>
]]></content:encoded>
			<wfw:commentRss>http://eremiya.net/2009/07/08/jquery-flot-tutorial-part-1/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
	</channel>
</rss>

