Location: PHPKode > scripts > Circle Chart using SVG > circle-chart-using-svg/test_circlechart.php
<?
include ("circlechart.php");

function cmp($attrObjectA,$attrObjectB)
{
	return $attrObjectA->m_fTotal > $attrObjectB->m_fTotal;
}

$arrCO2Emisions = array();

$arrCO2Emisions[] ="Allemagne 837.5 -6.4 342.9 319.9 165.3 9.4 302.1 124.2 168.9 121.7 120.6 0.31 10.15";
$arrCO2Emisions[] ="Australie 342.8 29.5 193.8 103.3 45.1 0.7 194.2 36.7 75.6 7.2 29.1 0.71 17.36";
$arrCO2Emisions[] ="Autriche 66.1 16.0 13.4 36.6 15.0 1.2 11.7 15.3 19.1 10.3 9.8 0.24 8.21";
$arrCO2Emisions[] ="Belgique 112.6 0.6 23.8 55.9 31.2 1.6 22.3 30.4 25.5 19.0 15.5 0.35 10.90";
$arrCO2Emisions[] ="Canada 531.9 22.1 116.9 245.2 169.8 0.0 123.7 89.1 150.5 41.8 126.8 0.71 16.93";
$arrCO2Emisions[] ="Coree 451.6 64.9 170.2 222.3 48.4 10.6 130.3 86.6 95.8 33.6 105.3 0.66 9.48";
$arrCO2Emisions[] ="Danemark 51.2 -6.6 16.3 23.4 10.8 0.7 23.3 5.2 12.2 3.9 6.6 0.24 9.52";
$arrCO2Emisions[] ="Espagne 303.4 33.4 82.9 177.3 43.2 0.0 94.7 58.1 98.0 17.4 35.2 0.41 7.48";
$arrCO2Emisions[] ="EtatsUnis 5652.3 15.6 2070.7 2323.3 1241.1 17.2 2274.1 621.4 1761.4 355.5 639.9 0.61 19.66";
$arrCO2Emisions[] ="Finlande 63.5 16.9 27.1 26.9 8.6 1.0 25.4 12.5 12.7 3.2 9.7 0.38 12.21";
$arrCO2Emisions[] ="France 377.1 2.3 50.4 240.6 86.1 0.0 36.9 80.0 140.8 75.8 43.4 0.21 6.16";
$arrCO2Emisions[] ="Grece 90.5 26.0 37.2 49.0 4.2 0.2 43.7 10.3 20.3 8.4 7.8 0.60 8.26";
$arrCO2Emisions[] ="Hongrie 55.4 -9.3 14.9 16.2 24.3 0.1 20.3 7.6 10.1 9.3 8.2 0.95 5.46";
$arrCO2Emisions[] ="Irlande 42.4 38.6 10.3 23.9 8.2 0.0 15.6 4.9 11.1 6.2 4.6 0.35 10.86";
$arrCO2Emisions[] ="Islande 2.2 16.3 0.4 1.8 0.0 0.0 0.0 0.8 0.7 0.0 0.7 0.25 7.71";
$arrCO2Emisions[] ="Italie 433.2 8.8 49.9 248.3 133.8 1.3 141.2 76.8 117.0 52.5 45.8 0.35 7.47";
$arrCO2Emisions[] ="Japon 1206.9 14.6 392.6 650.5 163.1 0.7 361.3 249.3 253.1 68.3 274.9 0.21 9.47";
$arrCO2Emisions[] ="Luxembourg 9.3 -13.6 0.4 6.5 2.5 0.0 0.8 1.5 5.4 1.4 0.2 0.36 20.80";
$arrCO2Emisions[] ="Mexique 365.2 19.0 29.6 245.7 89.9 0.0 114.8 48.1 104.6 20.7 76.8 0.97 3.64";
$arrCO2Emisions[] ="Norvege 33.1 9.9 3.4 21.5 8.1 0.1 0.4 7.2 12.3 0.9 12.3 0.18 7.28";
$arrCO2Emisions[] ="NlleZelande 34.0 37.2 4.9 17.3 10.1 1.7 5.5 10.1 14.2 0.6 3.6 0.46 8.55";
$arrCO2Emisions[] ="PaysBas 177.9 7.7 31.6 62.9 82.0 1.4 50.3 34.3 33.9 18.5 40.9 0.35 11.02";
$arrCO2Emisions[] ="Pologne 282.9 -16.7 207.8 51.2 21.6 2.3 148.9 40.8 24.8 27.1 41.2 1.63 7.40";
$arrCO2Emisions[] ="Portugal 63.0 40.2 13.5 43.2 6.3 0.0 22.3 11.8 18.8 2.2 7.9 0.47 6.07";
$arrCO2Emisions[] ="Repslovaque 37.9 -22.2 15.4 9.1 13.2 0.2 8.2 9.6 6.2 4.3 9.6 1.50 7.04";
$arrCO2Emisions[] ="Reptcheque 115.0 -11.6 74.9 21.3 17.7 1.1 54.9 22.1 14.8 7.6 15.5 1.98 11.27";
$arrCO2Emisions[] ="RoyaumeUni 529.3 -4.9 137.0 193.5 197.9 0.9 158.2 67.6 131.4 83.8 88.2 0.38 8.94";
$arrCO2Emisions[] ="Suede 50.1 -3.9 9.9 38.3 1.8 0.1 7.4 12.6 22.0 2.5 5.7 0.17 5.62";
$arrCO2Emisions[] ="Suisse 42.8 -2.6 0.5 33.5 5.8 3.0 1.9 7.3 14.9 11.3 7.4 0.13 5.87";
$arrCO2Emisions[] ="Turquie 193.1 40.1 77.1 81.8 34.1 0.1 54.9 50.9 35.8 18.9 32.5 0.94 2.77";


class CCO2Emission
{
	var $m_strIndex;
	var $m_fTotal;
	var $m_fVariation;
	var $m_fCoal;
	var $m_fPetroleum;
	var $m_fGas;
	var $m_fOthers;
	var $m_fElectricity;	
	var $m_fIndustry;
	var $m_fTransport;
	var $m_fConsumer;
	var $m_fOthers;
	var $m_fCO2PIB;
	var $m_fCO2Hab;
}


// Path to write the svg file
$strPath ="c:\\temp\\co2emissions.svg";
$strPathHtml ="<html><head></head><body><embed src=\"$strPath\" style=\"width: " . SIZEWIDTHCM ." cm; height: " . SIZEHEIGHTCM ."cm\"></p></body></html>\n";

// Create a new chart
$chart = new CCircleChart($strPath);

// Attributes used in the chart, begining for the most important
$chart->m_dataChart->m_arrAttributes[] ="m_fTotal";
$chart->m_dataChart->m_arrAttributes[] ="m_fCO2PIB";
$chart->m_dataChart->m_arrAttributes[] ="m_fCO2Hab";

// Load the data into the chart
$co2emission = new CCO2Emission();
for ($i=0;$i<count($arrCO2Emisions);$i++)
{
	list($strCountry,$strTotal,$strVariation,$strCoal,$strPretroleum,$strGas,$strOthers,$strElectricity,
	     $strIndustry,$strTransport,$strConsumer,$strOthers,$strCO2PIB,$strCO2Hab) = explode(" ",$arrCO2Emisions[$i]);
	$co2emission->m_strIndex =$strCountry;
	$co2emission->m_fTotal =(float)$strTotal;
	$co2emission->m_fCO2PIB =(float)$strCO2PIB;	
	$co2emission->m_fCO2Hab =(float)$strCO2Hab;		
	$chart->m_dataChart->m_arrObjects[] =$co2emission;
}

// Order the data used in the chart
usort($chart->m_dataChart->m_arrObjects,"cmp");


// Position of the data circle
$chart->m_nCenterX=1100;
$chart->m_nCenterY =1900;
$chart->m_nRadius=500;
// Position of the attributes circle
$chart->m_nCenterXAttributes =1100;
$chart->m_nCenterYAttributes=600;
$chart->m_nRadiusAttributes =500;

//************************************************************************

// Header of the chart
$chart->HeaderSVG();
// Generate the scripts to change the info showed in the attributes circle
// when the mouse is over the data circle
$chart->GenScripts();

// Title of the chart
$chart->Text("CO2 EMISSIONS OCDE COUNTRIES",1100,2600,"Verdana","80","black","middle");
$chart->Text("(CO2 Total,CO2 / PIB,CO2 / HAB)",1100,2550,"Verdana","40","black","middle");

// Draw the text using the attribute m_strIndex, be carefully with the special characters
$chart->TextData();
// Draw the lines
$chart->LinesToCenter();
// Draw the data
$chart->DrawData();
// Close the svg file
$chart->CloseSVG();
//************************************************************************
// write the page linking the svg file
echo $strPathHtml;
?>
Return current item: Circle Chart using SVG