<?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>Cloud Connected &#187; api</title>
	<atom:link href="http://www.cloudconnected.fr/tag/api/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.cloudconnected.fr</link>
	<description>Thoughts of a french web developer</description>
	<lastBuildDate>Wed, 01 Feb 2012 08:53:57 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Google Chart PHP Library 0.4</title>
		<link>http://www.cloudconnected.fr/2010/05/15/google-chart-php-library-0-4/</link>
		<comments>http://www.cloudconnected.fr/2010/05/15/google-chart-php-library-0-4/#comments</comments>
		<pubDate>Sat, 15 May 2010 08:20:37 +0000</pubDate>
		<dc:creator>Rémi</dc:creator>
				<category><![CDATA[Non classé]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[chart]]></category>
		<category><![CDATA[googlechart]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.cloudconnected.fr/?p=599</guid>
		<description><![CDATA[I released a new version of my PHP library for Google Chart API. Remember it&#8217;s still in heavy development (well, depending on my free time and my motivation, so &#8220;heavy&#8221; is relative), therefore don&#8217;t except anything bug-free or feature complete. Less rigid API Until this version, I was focusing on implementing strictly the Google Chart [...]]]></description>
			<content:encoded><![CDATA[<p>I released a new version of <a href="/2010/04/28/announcing-googlechart-php-library-0-3/">my PHP library for Google Chart API</a>. Remember it&#8217;s still in heavy development (well, depending on my free time and my motivation, so &#8220;heavy&#8221; is relative), therefore don&#8217;t except anything bug-free or feature complete.</p>
<h3>Less rigid API</h3>
<p>Until this version, I was focusing on implementing strictly the Google Chart API. However, I eventually realize that the API is sometimes too rigid. For example, say you want to hide an axis. You have to specify &#8220;<code>_</code>&#8221; (underscore) as the 5th value (<code>axis_or_tick</code>) in the <code>chxs</code> parameter (values are separated by a coma). Looks easy right? Except it is NOT ok to omit the first 4th values. So you have to specify the <code>label_color</code>, <code>font_size</code> and <code>alignment</code> before, in order to be able to hide your axis.</p>
<p>In version 0.3, you had to do exactly that, by using <code>setStyle</code> and specifying the 4th parameter (<code>$axis_or_tick</code>). If you wonder why it&#8217;s not the 5th, it&#8217;s because the &#8220;axis index&#8221; value is calculated on runtime. Fortunatly, you could pass <code>null</code> as the value for the parameter, and the library will replace them by the default value. Example:</p>
<pre>
$axis = new GoogleChartAxis('x');
$axis->setStyle(null, null, null, '_');
</pre>
<p>In version 0.4, the <code>setStyle</code> method as been removed and splitted into multiple methods <code>setLabelColor</code>, <code>setFontSize</code>, <code>setLabelAlignment</code>, <code>setDrawLine</code>, <code>setDrawTickMarks</code> and <code>setTickColor</code>. Now you don&#8217;t need to worry about how many parameter you have to set, just call the method you want and the library will take care of setting the appropriate intermediate values. Example:</p>
<pre>
$axis = new GoogleChartAxis('x');
$axis->setDrawLine(false)->setDrawTickMarks(false);
</pre>
<h3>More abstraction</h3>
<p>This version also comes up with a set of features to simplify chart creation. For example, one of my favorite is <code>setBorder</code> method for Shape Markers (<code>GoogleChartShapeMarker</code>).</p>
<p>To create a border in a shape with Google Chart API, you need to create another similar marker below the first one (think z-order), with a different color and a slightly bigger size. Well, this can be done exactly this way in version 0.3. However, starting version 0.4, the <code>setBorder</code> method does the job for you. Just specify a color and the size of the border, and it will create the second marker automatically. Not only this is more convenient and easy to write, but this is also faster and uses less memory.</p>
<h3>New features</h3>
<p>This version adds support for Dynamic Icon. Because icons can be either &#8220;freestanding&#8221; (used as a chart) or used as marker, I had to refactor the base class. Now the base class is <code>GoogleChartApi</code> which holds the logic to query the API. <code>GoogleChart</code> and <code>GoogleChartIcon</code> extends this class, so you can use a <code>GoogleChartIcon</code> exactly the same way as a chart.</p>
<p>Example:</p>
<pre>
require '../lib/icons/GoogleChartIconNote.php';

$chart = new GoogleChartIconNote('Hello world');
$chart->setTitle('Example');
$chart->setTextColor('D01F3C');

header('Content-Type: image/png');
echo $chart;
</pre>
<p>To use a icon as a marker, use the new <code>addDynamicMarker</code> method. Example:</p>
<pre>
require '../lib/GoogleChart.php';
require '../lib/icons/GoogleChartIconNote.php';

$values = array();
for ($i = 0; $i &lt;= 10; $i += 1) {
	$values[] = rand(20,80);
}

$chart = new GoogleChart('ls', 500, 200);
$data = new GoogleChartData($values);
$chart->addData($data);

$marker = new GoogleChartIconNote('Hello');
$marker->setData($data);
$chart->addDynamicMarker($marker);

header('Content-Type: image/png');
echo $chart;
</pre>
<p>For the moment, only &#8220;note&#8221; icon (aka <a href="http://code.google.com/intl/fr-FR/apis/chart/docs/gallery/dynamic_icons.html#fun_style_note" rel="nofollow">Fun style notes with text and optional title</a>) are supported, but I&#8217;m working on it.</p>
<h3>Hey, the project has a new home!</h3>
<p>Yes, the project is now hosted by Google Code. Because there is already a shitload of abandonned projects named using every possible combinations of &#8220;google&#8221; &#8220;chart&#8221; and &#8220;php&#8221;, I had to use the (rather long) name &#8220;googlechartphplib&#8221;. So new home is here:<br />
<a href="http://code.google.com/p/googlechartphplib">http://code.google.com/p/googlechartphplib</a>. You&#8217;ll find source code, issue tracker, documentation and the new SVN access there.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.cloudconnected.fr/2010/05/15/google-chart-php-library-0-4/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Announcing GoogleChart PHP library 0.3</title>
		<link>http://www.cloudconnected.fr/2010/04/28/announcing-googlechart-php-library-0-3/</link>
		<comments>http://www.cloudconnected.fr/2010/04/28/announcing-googlechart-php-library-0-3/#comments</comments>
		<pubDate>Wed, 28 Apr 2010 15:02:39 +0000</pubDate>
		<dc:creator>Rémi</dc:creator>
				<category><![CDATA[Non classé]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[googlechart]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.cloudconnected.fr/?p=586</guid>
		<description><![CDATA[I&#8217;ve been playing around a lot with Google Chart API lately, mainly for fun to draw some charts based on my Last.fm profile (Last.fm provides a very nice API). Google Chart API is very powerful, but quite harsh to work with, and unfortunately I didn&#8217;t find any good and easy-to-use PHP library for it. There [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been playing around a lot with <a href="http://code.google.com/apis/chart/image_charts.html">Google Chart API</a> lately, mainly for fun to draw some charts based on my Last.fm profile (Last.fm provides a <a href="http://www.last.fm/api">very nice API</a>). Google Chart API is very powerful, but quite harsh to work with, and unfortunately I didn&#8217;t find any good and easy-to-use PHP library for it. There are <a href="https://groups.google.com/group/google-chart-api/web/useful-links-to-api-libraries?_done=/group/google-chart-api&#038;pli=1">some</a> but most of them are either not maintened or not fully working. So I ended up writting my own library. A few weeks ago, I used it for a project at work, improved it a bit and it worked like a charm. Eventually I decided to release it open-source (MIT license). It&#8217;s provided &#8220;as is&#8221;, without warranty of any kind. I just hope that it might be useful to somebody else as well, who knows?</p>
<h3>Quick introduction</h3>
<p>The library&#8217;s goal is to provide an easy way to build requests to Google Chart API, and especially to ease the painfull strings concatenation with comas, pipes, colons, etc. If you&#8217;ve already tried Google Chart API, you know what I mean! :-) So I wrote a couple of class, that allows to quickly create a chart (<code>GoogleChart</code>), add data series (<code>GoogleChartData</code>), axes (<code>GoogleChartAxis</code>) and markers (<code>GoogleChartMarker</code>), and compute an URL (for GET requests) or an array of parameters (for POST requests). It can even fetch the image for you (via GET or POST) so that you can display it directly (or cache it, or do whatever you want with it).</p>
<p><span id="more-586"></span></p>
<p>I wanted to stick really closely to the actual Google Chart API. I hate having to fight with a library when I wanted to do some fancy stuffs with the API. So most of the time, the library will only provides an set of convenient setters stricly mapped on the API specification with almost no additional logic (there is also an universal setter if the setter you need is unimplemented yet. ;-) But YOU will have to check in the Google documentation for the list of supported parameters, or how to do some advanced stuff (compound charts, anyone?). If you give an unsupported parameter, you might get some unexepected results from Google Chart API. Only the cases that would makes the API send a error are checked.</p>
<p>In other words: this library is only an interface, the PHP logic is kept to the minimum. One exception here though: the library provide an autoscaling feature, because scaling manually your chart is a pain in the ass (this feature can be disabled if you want). Therefore if you&#8217;re not ready to read at least some of the Google Chart API documentation, this tool might not be for you.</p>
<h3>A quick example</h3>
<p>One quick example on how to create a line chart with 3 lines, 2 axis and some data markers.</p>
<pre>
require '../lib/GoogleChart.php';
require '../lib/markers/GoogleChartTextMarker.php';
require '../lib/markers/GoogleChartShapeMarker.php';

// create some random values
$values = array(
	array(),
	array(),
	array()
);
$n = 10;
for ($i = 0; $i &lt;= $n; $i += 1) {
	$v = rand($i , $i*10);
	$values[0][] = $v;
	$values[1][] = $v - $i;
	$values[2][] = rand(100 - ($i+10),100 - 10*$i);
}

// create the chart and define some options
$chart = new GoogleChart('lc', 400, 200);
$chart-&gt;setGridLines(10,10);
$chart-&gt;setLegendPosition('r');
$chart-&gt;setFill('ffffcc');
$chart-&gt;setGradientFill(45, array('cccccc', 'ffffff', 'cccccc'), GoogleChart::CHART_AREA);
$chart-&gt;setTitle('Us versus the others.');
$chart-&gt;setTitleStyle('999999', 20);

// create the first line
$line = new GoogleChartData($values[0]);
$line-&gt;setLegend('Us');
$chart-&gt;addData($line);

// add markers to this line
$marker = new GoogleChartShapeMarker(GoogleChartShapeMarker::X);
$marker-&gt;setData($line);
$marker-&gt;setColor('6699cc');
$chart-&gt;addMarker($marker);

$marker = new GoogleChartTextMarker(GoogleChartTextMarker::VALUE);
$marker-&gt;setData($line);
$chart-&gt;addMarker($marker);

// define a dotted line (not displayed in the legend)
$line = new GoogleChartData($values[1]);
$line-&gt;setStyle(2,2,2);
$line-&gt;setColor('6699cc');
$chart-&gt;addData($line);

// define a red line
$line = new GoogleChartData($values[2]);
$line-&gt;setLegend('The others');
$line-&gt;setColor('ff0000');
$chart-&gt;addData($line);

// add markers
$marker = new GoogleChartShapeMarker(GoogleChartShapeMarker::CIRCLE);
$marker-&gt;setData($line);
$marker-&gt;setColor('ff0000');
$chart-&gt;addMarker($marker);

// add axis
$y_axis = new GoogleChartAxis('y');
$chart-&gt;addAxis($y_axis);

$x_axis = new GoogleChartAxis('x');
$chart-&gt;addAxis($x_axis);

// debug the chart
if ( isset($_GET['debug']) ) {
	var_dump($chart->getQuery());
	echo $chart->validate();
	echo $chart->toHtml();
}
// display the chart
else{
	header('Content-Type: image/png');
	echo $chart;
}
</pre>
<p>Generated chart (I copy/pasted the generated URL, this is not the actual PHP code):</p>
<p><img src="http://chart.apis.google.com/chart?cht=lc&#038;chs=400x200&#038;chg=10,10&#038;chf=bg,s,ffffcc|c,lg,45,cccccc,0,ffffff,0.5,cccccc,1&#038;chtt=Us+versus+the+others.&#038;chts=999999,20&#038;chd=t:0,10,11,24,31,27,7,34,28,18,59|0,9,9,21,27,22,1,27,20,9,49|95,90,84,75,74,72,42,71,51,12,46&#038;chco=4D89F9,6699cc,ff0000&#038;chls=2|2,2,2|2&#038;chdl=Us||The+others&#038;chdlp=rs&#038;chm=x,6699cc,0,-1,10|N,336699,0,-1,10|o,ff0000,2,-1,10&#038;chxt=y,x" alt="Result chart" /></p>
<h3>Requirements and limitations</h3>
<p>GoogleChart PHP library works with PHP 5.2 (maybe works with other version as well, I don&#8217;t know), and doesn&#8217;t require any additional library. It&#8217;s released under the MIT license. Current version is 0.3, meaning that a lot of features are unimplemented yet (but otherwise it works fine, believe me ;-). Current major limitations includes :</p>
<ul>
<li>Only support <a href="http://code.google.com/apis/chart/docs/data_formats.html#text">Basic Text Format</a> and <a href="http://code.google.com/apis/chart/docs/data_formats.html#data_scaling">Text Format with Custom Scaling</a>.</li>
<li>Only tested with <a href="http://code.google.com/apis/chart/docs/gallery/line_charts.html">Line Charts</a>, <a href="http://code.google.com/apis/chart/docs/gallery/map_charts.html">Map Charts</a> and <a href="http://code.google.com/apis/chart/docs/gallery/bar_charts.html">Bar Charts</a>. It&#8217;s designed to handle any type though, so with a little bit of luck it might works for other charts as well.</li>
</ul>
<p>And also, because it&#8217;s a side project I do during my spare time, I only implement the features that I need for my other projets, and only when I need them. So if have different needs and you&#8217;re willing to help, you&#8217;re welcome!</p>
<h3>Download and install</h3>
<p>GoogleChart PHP library is available for download here: <del>http://redmine.kuerti.net/projects/googlechart/files</del> <a href="http://code.google.com/p/googlechartphplib">http://code.google.com/p/googlechartphplib</a>. The archive comes with plenty examples and Doxygen documentation. Just copy the content of the <code>lib</code> folder inside your project.</p>
<p>You can also checkout the latest SVN version here: <del><code>http://svn.kuerti.net/googlechart/trunk</code></del> <code>http://googlechartphplib.googlecode.com/svn/trunk/</code>.</p>
<p>Doxygen-generated <a href="http://googlechartphplib.cloudconnected.fr/doc/">documentation is available here</a>. This documentation is not always up-to-date nor complete, but I&#8217;m working on it, I promise.</p>
<h3>Send me feebacks, I love feedbacks</h3>
<p>Feedbacks are more than welcome! Feel to send feature requests, bug reports and more here as a comment, or (better) on <del>the project&#8217;s Redmine: http://redmine.kuerti.net/projects/googlechart</del> the project homepage in Google Code: <a href="http://code.google.com/p/googlechartphplib/">http://code.google.com/p/googlechartphplib/</a>. And if you&#8217;re a developer and interested on improving it, feel free, it&#8217;s open source! Mails are also always welcome at <code>remi at cloudconnected dot fr</code>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.cloudconnected.fr/2010/04/28/announcing-googlechart-php-library-0-3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

