Home > PHP > pChartでグラフ作成(折れ線グラフ)

pChartでグラフ作成(折れ線グラフ)

  • Posted by: R54
  • 2009年2月13日 15:32
  • PHP
PHPでグラフを描いてみようと言う事で、
オープンソースの『pChart』を使用してみたのでそのときのメモ。

ココからソースを落としてきてサーバにアップロード!!

以下、サンプルソース

example1.png
(クリックで拡大)
$weight = 配列;
$timestamp = 配列;

// Standard inclusions     
include("pChart/pData.class");
include("pChart/pChart.class");


$DataSet = new pData;

$DataSet->AddPoint($weight,"Serie1");
$DataSet->AddPoint($timestamp,"Serie2");
$DataSet->AddSerie("Serie1");

$DataSet->SetAbsciseLabelSerie("Serie2");
$DataSet->SetSerieName("weight","Serie1");

$DataSet->SetXAxisFormat("date");
$DataSet->SetYAxisName("weight"); 
$DataSet->SetYAxisUnit("kg"); 
 
// Initialise the graph
$Test = new pChart(700,300);
$Test->setFontProperties("Fonts/tahoma.ttf",8);
$Test->setGraphArea(70,30,650,200);
$Test->drawFilledRoundedRectangle(7,7,693,268,5,240,240,240);
$Test->drawRoundedRectangle(5,5,695,270,5,230,230,230);
$Test->drawGraphArea(255,255,255,TRUE); 
$Test->drawScale($DataSet->GetData(),$DataSet->GetDataDescription(),SCALE_NORMAL,150,150,150,TRUE,45,2);//SCALE_START0:0を基準とする。
$Test->drawGrid(4,TRUE,230,230,230,50); 
 
// Draw the 0 line
$Test->setFontProperties("Fonts/tahoma.ttf",6);
$Test->drawTreshold(0,143,55,72,TRUE,TRUE);
 
// Draw the line graph 
$Test->drawLineGraph($DataSet->GetData(),$DataSet->GetDataDescription());
$Test->drawPlotGraph($DataSet->GetData(),$DataSet->GetDataDescription(),3,2,255,255,255);
 
// Finish the graph
$Test->setFontProperties("Fonts/tahoma.ttf",8);
$Test->drawLegend(70,10,$DataSet->GetDataDescription(),255,255,255);
$Test->setFontProperties("Fonts/tahoma.ttf",10);
$Test->drawTitle(60,22,"weight graph",50,50,50,585);
$Test->Render("graph1.png");  


てな感じ!!
ドキュメントが英語だけど、結構簡単に手軽に出来るのでオススメ!!


Comments:0

Comment Form

Trackbacks:0

TrackBack URL for this entry
http://blog.route-54.com/mt/mt-tb.cgi/8
Listed below are links to weblogs that reference
pChartでグラフ作成(折れ線グラフ) from R54

Home > PHP > pChartでグラフ作成(折れ線グラフ)

Search
Feeds

Return to page top