線上書籍

Home

[982]PHP網站開發 進階應用技巧

<?php
//引入物件
include_once("pChart/pData.class");
include_once("pChart/pChart.class");

//定義資料
$DataSet = new pData;
$DataSet->ImportFromCSV("Sample/ck2.csv",",",array(1,2,3),TRUE,0);

$DataSet->AddAllSeries();
$DataSet->SetAbsciseLabelSerie();

//$DataSet->SetSerieName("造訪人數","counter");
//$DataSet->SetSerieName("國家","country");

//繪製圖表底圖
$Test = new pChart(600,300);
$Test->loadColorPalette("Sample/color.txt");

//設定各標記的字型
$Test->setFontProperties("Fonts/cwyen.ttf",12);
$Test->setGraphArea(70,50,570,250);
$Test->drawFilledRoundedRectangle(7,7,593,293,5,240,240,240);
$Test->drawRoundedRectangle(5,5,595,295,5,130,130,130);
$Test->drawGraphArea(255,255,200,TRUE);
$Test->drawScale($DataSet->GetData(),$DataSet->GetDataDescription(),SCALE_NORMAL,150,150,150,TRUE,0,0,TRUE);
$Test->drawGrid(4,TRUE,230,230,230,50);


//繪製線段
//長條圖
//$Test->drawBarGraph($DataSet->GetData(),$DataSet->GetDataDescription(),TRUE);
//曲線圖
//$Test->drawCubicCurve($DataSet->GetData(),$DataSet->GetDataDescription());
//折線圖
$Test->drawLineGraph($DataSet->GetData(),$DataSet->GetDataDescription());
//繪製圓點
$Test->drawPlotGraph($DataSet->GetData(),$DataSet->GetDataDescription(),3,2,255,255,255);

// Finish the graph
$Test->setFontProperties("Fonts/cwheib.ttf",14);
$Test->drawLegend(450,70,$DataSet->GetDataDescription(),255,255,255);

$Test->setFontProperties("Fonts/cwheib.ttf",20);
$Test->drawTitle(200,35,"2009年訪客來源分析",0,0,0,-1,-1,true);


$Test->Render("demo1.png");
?>
<body bgcolor="white">
<img src='demo1.png' >
</body>