Created
February 6, 2014 08:48
-
-
Save KimiyukiYamauchi/8840550 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| // 出力形式、文字コードの指定 | |
| header('Content-type: text/html; charset=UTF-8'); | |
| // 必要パッケージの読み込み | |
| require_once('jpgraph/jpgraph.php'); | |
| require_once('jpgraph/jpgraph_bar.php'); | |
| // データの設定 | |
| $datax=array(); | |
| $datay=array(); | |
| require 'MDB2.php'; | |
| require 'connect_mysql.php'; | |
| $db = connect_mysql(); | |
| $rows = $db->queryAll('SELECT ename, sal FROM employees'); | |
| foreach ($rows as $row) { | |
| // print "$row[0], $row[1] \n"; | |
| $datax[] = $row[0]; | |
| $datay[] = $row[1]; | |
| } | |
| //var_dump($datax); | |
| //var_dump($datay); | |
| // グラフの作成 | |
| //$graph = new Graph(500,150); | |
| $graph = new Graph(800,500); | |
| $graph->SetScale('textlin'); | |
| $graph->SetMargin(100,20,60,40); | |
| // タイトルを設定 | |
| $graph->title->Set('給与グラフ'); | |
| //$graph->title->SetColor('white'); | |
| $graph->title->SetColor('black'); | |
| // タイトルのフォントを日本語に | |
| $graph->title->SetFont(FF_GOTHIC, FS_NORMAL, 16); | |
| // X軸,Y軸のフォントを設定 | |
| $graph->xaxis->SetFont(FF_GOTHIC); | |
| $graph->yaxis->SetFont(FF_GOTHIC); | |
| // グラフの説明のフォント設定 | |
| //$graph->legend->SetFont(FF_GOTHIC, FS_NORMAL); | |
| // ラベルの設定 | |
| $graph->xaxis->SetTickLabels($datax); | |
| $graph->yaxis->SetLabelFormatCallback('yLabelFormat'); | |
| $graph->yaxis->HideTicks(true,false); | |
| // 棒グラフオブジェクトの生成 | |
| $bplot = new BarPlot($datay); | |
| // 棒グラフの幅を設定 | |
| $bplot->SetWidth(0.6); | |
| // 棒グラフの説明を入れる | |
| //$bplot->SetLegend('アクセス数の推移'); | |
| // 棒グラフにグラデーションをかける | |
| $bplot->SetFillGradient('pink','red',GRAD_HOR); | |
| // グラフに棒グラフを追加 | |
| $graph->Add($bplot); | |
| // グラフ描画 | |
| $graph->Stroke(); | |
| function yLabelFormat($aLabel) { | |
| return number_format($aLabel); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment