<?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>Dave Rowe's Blog &#187; chartdirector</title>
	<atom:link href="http://blog.roweware.com/tag/chartdirector/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.roweware.com</link>
	<description>Ramblings about things I think I know...</description>
	<lastBuildDate>Wed, 14 Jul 2010 17:45:52 +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>ChartDirector with PHP</title>
		<link>http://blog.roweware.com/2010/03/02/chartdirector-with-php/</link>
		<comments>http://blog.roweware.com/2010/03/02/chartdirector-with-php/#comments</comments>
		<pubDate>Tue, 02 Mar 2010 14:30:11 +0000</pubDate>
		<dc:creator>Dave Rowe</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[General]]></category>
		<category><![CDATA[chartdirector]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[help]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://blog.roweware.com/?p=189</guid>
		<description><![CDATA[For a project, we have the need to create charts dynamically from data.  In another project, we&#8217;ve used ChartDirector for this.  It has worked great there, so we pulled it into this project as well.  Now, the type of charts I was working with in particular is a stacked percentage chart, which is kind of [...]]]></description>
			<content:encoded><![CDATA[<p>For a project, we have the need to create charts dynamically from data.  In another project, we&#8217;ve used <a href="http://www.advsofteng.com/">ChartDirector</a> for this.  It has worked great there, so we pulled it into this project as well.  Now, the type of charts I was working with in particular is a stacked percentage chart, which is kind of like a mash between a pie chart and a traditional bar chart.  An example:</p>
<p><a href="http://blog.roweware.com/wp-content/uploads/2010/03/percentbar.png"><img class="alignnone size-full wp-image-191" title="percentbar" src="http://blog.roweware.com/wp-content/uploads/2010/03/percentbar.png" alt="Percentage Bar" width="510" height="330" /></a></p>
<p>Now, with dynamic data, you can&#8217;t predict what your data will look like, and your code needs to be flexible enough to handle any situation without causing headaches for the user.  With ChartDirector, you pass in datasets via arrays across the chart, so for example the above datasets would be created by:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p189code3'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p1893"><td class="code" id="p189code3"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$data0</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">100</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">125</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">245</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">147</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">67</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$data1</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">85</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">156</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">179</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">211</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">123</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$data2</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">97</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">87</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">56</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">267</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">157</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Such that, the numbers line up in the arrays (vertically) in how they correspond to the resulting chart.  In my situation and test data, I found I had a situation like the following:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p189code4'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p1894"><td class="code" id="p189code4"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$data0</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">100</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">125</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">147</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">67</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$data1</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">85</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">156</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">211</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">123</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$data2</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">97</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">87</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">267</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">157</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>So, the bar for the 3rd item in the chart would be distributed equally as 33.33% when, in fact, there was no data.  I assumed the chart would display a blank spot for that bar.  After searching the less than optimal support forums (to no fault of the creators / maintainers), I found I needed to instead use a constant defined in the ChartDirector code &#8211; &#8216;NoValue&#8217;, where I had&#8230;wait for it&#8230;.no value.  Putting a small check in my code to replace zeros with &#8216;NoValue&#8217; proved to produce the results I was after.</p>
<p>Note to fellow developers: If you&#8217;re posting in a forum for assistance, please be more verbose in your subject line.  It <em>really</em> helps with searching if the subject can provide some bit of context around what the problem is.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.roweware.com/2010/03/02/chartdirector-with-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
