JpGraphでXMLデータをグラフ化する

下記のXMLを元にPHPのJpGraphでグラフを出力してみた。

<?xml version="1.0" encoding="UTF-8"?> 
<datas> 
  <data> 
    <name>Windows</name> 
    <price>99</price> 
  </data> 
  <data> 
    <name>Mac</name> 
    <price>94</price> 
  </data> 
  <data> 
    <name>Linux</name> 
    <price>30</price> 
  </data> 
</datas> 


<?php 
require_once("jpgraph.php"); 
require_once("jpgraph_pie.php"); 
require_once("jpgraph_pie3d.php"); 

$xml = new SimpleXMLElement('test.xml',0,true); 
$data_arr = $xml->data; 

$i = 0; 
$nameArray; 
$valueArray; 
foreach($data_arr as $row){ 
  $nameArray[$i] = $row->name; 
  $valueArray[$i] = $row->price; 
  $i = $i+1; 
} 
$data_legends = array($nameArray[0], $nameArray[1], $nameArray[2]); 
$data = array($valueArray[0],$valueArray[1],$valueArray[2]); 

$graph = new PieGraph(350,300,"auto"); 
$graph->title->Set("piece of shit graph"); 
$graph->legend->Pos(0.05, 0.95, "right", "bottom"); 

$pie = new PiePlot3D($data); 
$pie->SetSize(0.4); 
$pie->SetCenter(0.5,0.5); 
$pie->SetLegends($data_legends); 

$graph->Add($pie); 
$graph->img->SetImgFormat('gif'); 
$graph->Stroke(); 
?>