<?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>36Flavours.com &#187; class</title>
	<atom:link href="http://36flavours.com/tag/class/feed/" rel="self" type="application/rss+xml" />
	<link>http://36flavours.com</link>
	<description>A taste of something different...</description>
	<lastBuildDate>Mon, 19 Apr 2010 20:01:53 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Simple PHP Sparklines</title>
		<link>http://36flavours.com/2008/04/simple-php-sparklines/</link>
		<comments>http://36flavours.com/2008/04/simple-php-sparklines/#comments</comments>
		<pubDate>Sat, 12 Apr 2008 22:16:24 +0000</pubDate>
		<dc:creator>Steve Whiteley</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[class]]></category>
		<category><![CDATA[gdlib]]></category>
		<category><![CDATA[sparkline]]></category>

		<guid isPermaLink="false">http://sha.re.it/?p=15</guid>
		<description><![CDATA[Whilst designing a new layout for one of my current projects, I wanted to be able to provide the end user with the ability to quickly scan over a series of statistics. The main page should act as overview of everything that is going on, therefore I wanted to avoid overcrowding it with lots of [...]]]></description>
			<content:encoded><![CDATA[<p class="first">Whilst designing a new layout for one of my current projects, I wanted to be able to provide the end user with the ability to quickly scan over a series of statistics.</p>
<p>The main page should act as overview of everything that is going on, therefore I wanted to avoid overcrowding it with lots of large graphs and instead simply show the basic trends.</p>
<p>A few months back I came across an implementation of <a title="Sparkline From Wikipedia, the free encyclopedia" href="http://en.wikipedia.org/wiki/Sparkline" target="_blank">Sparklines</a> &#8211; data-intense, design-simple, word-sized graphics &#8211; which are often used to demonstrate stock market activity in a simple visual graphic.</p>
<p>I was just going to use a pre-made script from the many already available, but instead decided to knock one up myself and created a small <a title="PHP Class Source Code" href="http://sha.re.it/wp-content/examples/sparkline/sparkline.class.phps" target="_blank">PHP Class</a> to generate and output a sparkline image using the GD Library.</p>
<p>To create a sparkline I can now simply include the class and then initiate it in a variation of the following:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$sparkline</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Sparkline<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$sparkline</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>data <span style="color: #339933;">=</span> <span style="color: #990000;">Array</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">3</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">38</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">2</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">8</span><span style="color: #339933;">,</span> <span style="color: #339933;">...</span> <span style="color: #339933;">,</span><span style="color: #cc66cc;">38</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">13</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">4</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">23</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$sparkline</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>output<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Display image</span></pre></div></div>

<p>This PNG image is generated and output to the browser:</p>
<p style="text-align: center;"><img src="http://sha.re.it/wp-content/examples/sparkline/example1.php" alt="Example Sparkline" width="120" height="40" /></p>
<p style="text-align: left;">A number of other setup options are available to customise the output further:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$sparkline</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>bg <span style="color: #339933;">=</span> <span style="color: #0000ff;">'#000000'</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Background colour</span>
<span style="color: #000088;">$sparkline</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>width <span style="color: #339933;">=</span> <span style="color: #cc66cc;">150</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$sparkline</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>height <span style="color: #339933;">=</span> <span style="color: #cc66cc;">50</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$sparkline</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>line <span style="color: #339933;">=</span> <span style="color: #0000ff;">'#336699'</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Line colour</span>
<span style="color: #000088;">$sparkline</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>points <span style="color: #339933;">=</span> <span style="color: #0000ff;">'#333333'</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Start &amp;amp; end points</span>
<span style="color: #000088;">$sparkline</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>thickness <span style="color: #339933;">=</span> <span style="color: #cc66cc;">2</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Line thickness</span>
<span style="color: #000088;">$sparkline</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>scale <span style="color: #339933;">=</span> <span style="color: #cc66cc;">5</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Anti-aliasing scale size</span>
<span style="color: #000088;">$sparkline</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>output<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'saved/test.png'</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Save to location and display</span></pre></div></div>

<p style="text-align: center;"><img src="http://sha.re.it/wp-content/examples/sparkline/example2.php" alt="Customised Sparkline" width="180" height="60" /></p>
<p style="text-align: left;">All colours must be provided in hexadecimal format and if you are attempting to save the image the destination location must be writeable by Apache.</p>
<p style="text-align: left;">The <a title="PHP Class Source Code" href="http://sha.re.it/wp-content/examples/sparkline/sparkline.class.phps" target="_blank">Sparkline PHP Class source code</a> is available for anyone to use as they may like, although I must confess it hasn&#8217;t been fully tested as yet!</p>
]]></content:encoded>
			<wfw:commentRss>http://36flavours.com/2008/04/simple-php-sparklines/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
