<?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>Ordo Ab Chao - Il blog di Rocco Agostino &#187; PHP</title>
	<atom:link href="http://blog.roccoagostino.eu/category/informatica/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.roccoagostino.eu</link>
	<description>Il mio blog personale in cui si discute di libri,musica,scrittura,poesia,video,foto,news,attualità,informatica e tecnologia. Un &#34;corner&#34; da condividere con voi che commentate,criticate o apprezzate.</description>
	<lastBuildDate>Fri, 18 Nov 2011 05:48:49 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<atom:link rel='hub' href='http://blog.roccoagostino.eu/?pushpress=hub'/>
		<item>
		<title>PHP &#8211; Creare grafici con la libreria PHPGraphLib</title>
		<link>http://blog.roccoagostino.eu/2009/09/13/php-creare-grafici-con-la-libreria-phpgraphlib/</link>
		<comments>http://blog.roccoagostino.eu/2009/09/13/php-creare-grafici-con-la-libreria-phpgraphlib/#comments</comments>
		<pubDate>Sun, 13 Sep 2009 16:37:25 +0000</pubDate>
		<dc:creator>Rocky</dc:creator>
				<category><![CDATA[In evidenza]]></category>
		<category><![CDATA[Informatica]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[how-to]]></category>
		<category><![CDATA[programmazione]]></category>

		<guid isPermaLink="false">http://blog.roccoagostino.eu/?p=330</guid>
		<description><![CDATA[<img src="http://www.roccoagostino.eu/wp/wp-content/uploads/php_ico.jpg" width="32" height="32" alt="" title="PHP" /><br/>PHPGraphLib è una libreria "preconfezionata", orientata agli oggetti e scritta in php che utilizza le librerie GD. Essa è destinata alla creazione di grafici per l'inserimento di questi ultimi in pagine web. I grafici permettono di mostrare a tutti i dati o risultati numerici in maniera più chiara tramite l'utilizzo di immagini e colori.]]></description>
			<content:encoded><![CDATA[<img src="http://www.roccoagostino.eu/wp/wp-content/uploads/php_ico.jpg" width="32" height="32" alt="" title="PHP" /><br/><p><strong>PHPGraphLib</strong> è una libreria &#8220;preconfezionata&#8221;, orientata agli oggetti e scritta in php che utilizza le librerie GD. Essa è destinata alla creazione di grafici per l&#8217;inserimento di questi ultimi in pagine web. I grafici permettono di mostrare a tutti i dati o risultati numerici in maniera più chiara tramite l&#8217;utilizzo di immagini e colori. </p>
<p><span id="more-330"></span></p>
<p>L&#8217;uso della libreria facilita il compito agli sviluppatori meno esperti anche perché include un sistema di gestione degli errori molto efficace. I risultati ottenibili con questa libreria sono veramente stupefacenti, la potenza del codice inserito nell&#8217;unica pagina di PHPGraphLib possono essere utilizzati al massimo, date le piccole dimensioni di quest&#8217;ultima.<br />
Sul <a href="http://www.ebrueggeman.com/" target="_blank">sito</a> dell&#8217;autore (Elliott Brueggeman) possiamo trovare la pagina di download da dove scaricare la libreria, disporre della guida ufficiale e di alcuni esempi testuali e video.<br />
Per potere utilizzare PHPGraphLib bisogna salvare i due file contenuti nella libreria, “phpgraphlib.php” e “phpgraphlib_pie.php”, in una cartella. Successivamente occorrerà modificare il file php.ini ed eliminare il commento ( ; ) alla riga “extension=php_gd2.dll” nel caso sia commentata.<br />
Per ultimo occorrerà includere il file *.php della libreria nella nostra pagina php e scrivere il codice per creare il grafico.<br />
<em>Nota: bisogna creare in grafico in una pagina php a parte e richiamarla come imagine nella pagine dove vogliamo visualizzare il grafico.</em></p>
<p>&nbsp;</p>
<p>Vediamo dei semplici esempi:</p>
<p>&nbsp;</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">include</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;phpgraphlib.php&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
<span style="color: #000088;">$graph</span><span style="color: #339933;">=</span><span style="color: #000000; font-weight: bold;">new</span> PHPGraphLib<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">500</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">350</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$data</span><span style="color: #339933;">=</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">12124</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">5535</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">43373</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">22223</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">90432</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">23332</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">15544</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">24523</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">32778</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">38878</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">28787</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">33243</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">34832</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">32302</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$graph</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addData</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$graph</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setTitle</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Widgets Produced&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$graph</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setGradient</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;red&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;maroon&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$graph</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">createGraph</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>&nbsp;</p>
<p>salviamolo come &#8220;immagine.php&#8221; e richiamiamo il grafico nella pagina htlm con</p>
<p>&nbsp;</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">img</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;immagine.php&quot;</span><span style="color: #66cc66;">/</span>&gt;</span></pre></div></div>

<p>&nbsp;</p>
<p>il risultato è il seguente:</p>
<p>&nbsp;</p>
<p><a href="http://www.roccoagostino.eu/wp/wp-content/uploads/2009/09/grafico.JPG"><img src="http://www.roccoagostino.eu/wp/wp-content/uploads/2009/09/grafico.JPG" alt="grafico" title="grafico" width="492" height="333" class="aligncenter size-full wp-image-331" /></a></p>
<p>&nbsp;</p>
<p>Nella pagina <a href="http://blog.roccoagostino.eu/statistiche/" target="_blank">Statistiche</a> di questo blog ho utilizzato queste librerie.<br />
Nel caso del diagramma a torte, per esempio, passo dinamicamente i valori da diagrammare in questo modo:</p>
<p>&nbsp;</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">img</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;&lt;?php echo &quot;</span>statistiche_torta.php?a<span style="color: #66cc66;">=</span>$a&amp;r<span style="color: #66cc66;">=</span>$r&amp;s<span style="color: #66cc66;">=</span>$s&amp;m<span style="color: #66cc66;">=</span>$m<span style="color: #ff0000;">&quot; ?/&gt;</span></span>&quot; /&gt;</pre></div></div>

<p>&nbsp;</p>
<p>Nel file &#8221; statistiche_torta.php&#8221;</p>
<p>&nbsp;</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">    <span style="color: #b1b100;">include</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;phpgraphlib.php&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">include</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;phpgraphlib_pie.php&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000088;">$a</span><span style="color: #339933;">=</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'a'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$r</span><span style="color: #339933;">=</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'r'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$s</span><span style="color: #339933;">=</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'s'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$m</span><span style="color: #339933;">=</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'m'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000088;">$graph</span><span style="color: #339933;">=</span><span style="color: #000000; font-weight: bold;">new</span> PHPGraphLibPie<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">450</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">250</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$data</span><span style="color: #339933;">=</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Aggregatori&quot;</span><span style="color: #339933;">=&gt;</span><span style="color: #000088;">$a</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;Motori di ricerca&quot;</span><span style="color: #339933;">=&gt;</span><span style="color: #000088;">$r</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;Social Network&quot;</span><span style="color: #339933;">=&gt;</span><span style="color: #000088;">$s</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;E.mail&quot;</span><span style="color: #339933;">=&gt;</span><span style="color: #000088;">$m</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$graph</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addData</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
    <span style="color: #000088;">$graph</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setLabelTextColor</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;silver&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$graph</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setLegendColor</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;silver&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$graph</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setLegendOutlineColor</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;white&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>    
    <span style="color: #000088;">$graph</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setTitle</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Parlano di me....&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$graph</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setLabelTextColor</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;50,50,50&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$graph</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setLegendTextColor</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;50,50,50&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$graph</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">createGraph</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>&nbsp;</p>
<p>Ovviamente è possibile passare direttamente l&#8217;array da diagrammare oppure ricavare i valori eseguendo query in mysql, complicando il codice.</p>
<p>&nbsp;</p>
<p><strong>Enjoy it!</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.roccoagostino.eu/2009/09/13/php-creare-grafici-con-la-libreria-phpgraphlib/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
<!-- This Quick Cache file was built for (  blog.roccoagostino.eu/category/informatica/php/feed/ ) in 0.68958 seconds, on Feb 6th, 2012 at 1:20 pm UTC. -->
<!-- This Quick Cache file will automatically expire ( and be re-built automatically ) on Feb 13th, 2012 at 1:20 pm UTC -->
