<?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>Made of Everything You&#039;re Not &#187; pchart</title>
	<atom:link href="http://blog.ericlamb.net/tag/pchart/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.ericlamb.net</link>
	<description>Thoughts on programming, people and life</description>
	<lastBuildDate>Wed, 11 Aug 2010 03:58:55 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>pChart &#8211; a PHP class to build charts</title>
		<link>http://blog.ericlamb.net/2009/09/pchart-a-php-class-to-build-charts/</link>
		<comments>http://blog.ericlamb.net/2009/09/pchart-a-php-class-to-build-charts/#comments</comments>
		<pubDate>Fri, 11 Sep 2009 13:00:43 +0000</pubDate>
		<dc:creator>Eric Lamb</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[charts]]></category>
		<category><![CDATA[graphs]]></category>
		<category><![CDATA[pchart]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://blog.ericlamb.net/?p=1459</guid>
		<description><![CDATA[In my never ending quest to find a replacement for JpGraph  I&#8217;ve covered charts built using JavaScript with the Google Visualization API and charts done with SWFs using Open Flash Charts (OFS). If you&#8217;re building web apps it&#8217;s easy to just stop there and consider yourself covered. I certainly thought so; until my conscience spoke [...]]]></description>
			<content:encoded><![CDATA[<p>In my never ending quest to find a replacement for JpGraph  I&#8217;ve covered charts built using JavaScript with the <a title="Google Visualization API Primer" href="http://blog.ericlamb.net/2009/03/google-visualization-api-primer/" onclick="return TrackClick('http%3A%2F%2Fblog.ericlamb.net%2F2009%2F03%2Fgoogle-visualization-api-primer%2F','Google+Visualization+API+Primer')" target="_self">Google Visualization API</a> and charts done with SWFs using <a title="Prettify Data with Open Flash Chart" href="http://blog.ericlamb.net/2009/06/pretty-data-with-open-flash-chart/" onclick="return TrackClick('http%3A%2F%2Fblog.ericlamb.net%2F2009%2F06%2Fpretty-data-with-open-flash-chart%2F','Prettify+Data+with+Open+Flash+Chart')" target="_self">Open Flash Charts</a> (OFS). If you&#8217;re building web apps it&#8217;s easy to just stop there and consider yourself covered. I certainly thought so; until my conscience spoke up that is.</p>
<div id="attachment_2473" class="wp-caption aligncenter" style="width: 310px"><a href="http://blog.ericlamb.net/wp-content/uploads/2009/09/pchart_example.png" onclick="return TrackClick('http%3A%2F%2Fblog.ericlamb.net%2Fwp-content%2Fuploads%2F2009%2F09%2Fpchart_example.png','pChart')"><img class="size-medium wp-image-2473" title="pChart " src="http://blog.ericlamb.net/wp-content/uploads/2009/09/pchart_example-300x157.png" alt="pChart " width="300" height="157" /></a><p class="wp-caption-text">pChart </p></div>
<p>The thought them comes creaping into my head, &#8220;Um&#8230; What about the JavaScript? How do you think those pretty charts and graphs will degrade?&#8221;.</p>
<p>Shit.</p>
<p>Not to take anything away from either of those programs; they&#8217;re very fun to work with and, relatively, easy to use. It&#8217;s just that they&#8217;re both rendered using JavaScript which is well and good provided your user has JavaScript enabled (and Flash too for OFS). It&#8217;d be a nice addition to provide an alternative when using either one of the previous programs.</p>
<p>This is where <a title="pChart" href="http://pchart.sourceforge.net/" onclick="return TrackClick('http%3A%2F%2Fpchart.sourceforge.net%2F','pChart')" target="_blank">pChart</a> comes in:</p>
<blockquote><p>pChart is a PHP class oriented framework designed to create aliased charts. Most of todays chart libraries have a cost, our project is intended to be free. Data can be retrieved from SQL queries, CSV files, or manually provided. This project is still under development and new features or fix are made every week.</p>
<p>Focus has been put on rendering quality introducing an aliasing algorithm to draw eye candy graphics. Rendering speed has been dramatically enhanced since the first version, we&#8217;ll still continue optimising the code!</p></blockquote>
<p>Implementation is pretty easy too:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// Standard inclusions</span>
<span style="color: #22f;">include</span><span style="color: #000;">&#40;</span><span style="color: #0000ff;">&quot;pChart/pData.class&quot;</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #22f;">include</span><span style="color: #000;">&#40;</span><span style="color: #0000ff;">&quot;pChart/pChart.class&quot;</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Dataset definition</span>
<span style="color: #000088;">$DataSet</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> pData<span style="color: #339933;">;</span>
<span style="color: #000088;">$DataSet</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>AddPoint<span style="color: #000;">&#40;</span><span style="color: #990000;">array</span><span style="color: #000;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">4</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">3</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">2</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">3</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">3</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">2</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">7</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">4</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">3</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">2</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">3</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">3</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">5</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">7</span><span style="color: #000;">&#41;</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$DataSet</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>AddSerie<span style="color: #000;">&#40;</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$DataSet</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>SetSerieName<span style="color: #000;">&#40;</span><span style="color: #0000ff;">&quot;Sample data&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;Serie1&quot;</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Initialise the graph</span>
<span style="color: #000088;">$Test</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> pChart<span style="color: #000;">&#40;</span><span style="color: #cc66cc;">700</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">230</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$Test</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>setFontProperties<span style="color: #000;">&#40;</span><span style="color: #0000ff;">&quot;Fonts/tahoma.ttf&quot;</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">10</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$Test</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>setGraphArea<span style="color: #000;">&#40;</span><span style="color: #cc66cc;">40</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">30</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">680</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">200</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$Test</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>drawGraphArea<span style="color: #000;">&#40;</span><span style="color: #cc66cc;">252</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">252</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">252</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$Test</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>drawScale<span style="color: #000;">&#40;</span><span style="color: #000088;">$DataSet</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>GetData<span style="color: #000;">&#40;</span><span style="color: #000;">&#41;</span><span style="color: #339933;">,</span><span style="color: #000088;">$DataSet</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>GetDataDescription<span style="color: #000;">&#40;</span><span style="color: #000;">&#41;</span><span style="color: #339933;">,</span>SCALE_NORMAL<span style="color: #339933;">,</span><span style="color: #cc66cc;">150</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">150</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">150</span><span style="color: #339933;">,</span><span style="color: #009900; font-weight: bold;">TRUE</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">2</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$Test</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>drawGrid<span style="color: #000;">&#40;</span><span style="color: #cc66cc;">4</span><span style="color: #339933;">,</span><span style="color: #009900; font-weight: bold;">TRUE</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">230</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">230</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">230</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">255</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Draw the line graph</span>
<span style="color: #000088;">$Test</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>drawLineGraph<span style="color: #000;">&#40;</span><span style="color: #000088;">$DataSet</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>GetData<span style="color: #000;">&#40;</span><span style="color: #000;">&#41;</span><span style="color: #339933;">,</span><span style="color: #000088;">$DataSet</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>GetDataDescription<span style="color: #000;">&#40;</span><span style="color: #000;">&#41;</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$Test</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>drawPlotGraph<span style="color: #000;">&#40;</span><span style="color: #000088;">$DataSet</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>GetData<span style="color: #000;">&#40;</span><span style="color: #000;">&#41;</span><span style="color: #339933;">,</span><span style="color: #000088;">$DataSet</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>GetDataDescription<span style="color: #000;">&#40;</span><span style="color: #000;">&#41;</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">3</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">2</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">255</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">255</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">255</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Finish the graph</span>
<span style="color: #000088;">$Test</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>setFontProperties<span style="color: #000;">&#40;</span><span style="color: #0000ff;">&quot;Fonts/tahoma.ttf&quot;</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">8</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$Test</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>drawLegend<span style="color: #000;">&#40;</span><span style="color: #cc66cc;">45</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">35</span><span style="color: #339933;">,</span><span style="color: #000088;">$DataSet</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>GetDataDescription<span style="color: #000;">&#40;</span><span style="color: #000;">&#41;</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">255</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">255</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">255</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$Test</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>setFontProperties<span style="color: #000;">&#40;</span><span style="color: #0000ff;">&quot;Fonts/tahoma.ttf&quot;</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">10</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$Test</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>drawTitle<span style="color: #000;">&#40;</span><span style="color: #cc66cc;">60</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">22</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;My pretty graph&quot;</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">50</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">50</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">50</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">585</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$Test</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>Render<span style="color: #000;">&#40;</span><span style="color: #0000ff;">&quot;Naked.png&quot;</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
?<span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span></pre></div></div>

<p>The above code produces something similar to:</p>
<div id="attachment_2477" class="wp-caption aligncenter" style="width: 310px"><a href="http://blog.ericlamb.net/wp-content/uploads/2009/09/pchart_example_line.png" onclick="return TrackClick('http%3A%2F%2Fblog.ericlamb.net%2Fwp-content%2Fuploads%2F2009%2F09%2Fpchart_example_line.png','pChart+Linechart+Example')"><img class="size-medium wp-image-2477" title="pChart Linechart Example" src="http://blog.ericlamb.net/wp-content/uploads/2009/09/pchart_example_line-300x98.png" alt="pChart Linechart Example" width="300" height="98" /></a><p class="wp-caption-text">pChart Linechart Example</p></div>
<p>One really cool addition the developers added was a little cmd script, buildAll.cmd, to automate the build of all the Example scripts on Windows machines. Just double click that and you&#8217;ll have all the graph images generated automatically.</p>
<p>It is recommended by the developers that caching is implemented but I haven&#8217;t really found the need for it yet.</p>
<p>A good idea, and one I&#8217;m going to be implementing, is to use charts and graphs created with OFC and create static image graphs for the noscript tags using pChart. Definitely a lot of work but it&#8217;ll add a bit of shiny to my programs. Yours too I think.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.ericlamb.net/2009/09/pchart-a-php-class-to-build-charts/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
