ソース掲示板




すべてから検索

キーワード   条件 表示 現行ログ 過去ログ トピックス 名前 本文
jpgraph の導入
日時: 2007/09/01 21:58
名前: lightbox



PHP4 用のライブラリを PHP5 でテストしています。

  サンプルによるテスト
拡張子:
<?php
set_include_path( "/user/php/jpgraph-1.21b/src" );

include ("jpgraph.php");
include ("jpgraph_bar.php");

$datay=array(12,8,19,3,10,5);

// Create the graph. These two calls are always required
$graph = new Graph(300,200,"auto");	
$graph->SetScale("textlin");

// Add a drop shadow
$graph->SetShadow();

// Adjust the margin a bit to make more room for titles
$graph->img->SetMargin(40,30,20,40);

// Create a bar pot
$bplot = new BarPlot($datay);
$graph->Add($bplot);

// Setup the titles
$graph->title->Set("A simple bar graph");
$graph->xaxis->title->Set("X-title");
$graph->yaxis->title->Set("Y-title");

$graph->title->SetFont(FF_FONT1,FS_BOLD);
$graph->yaxis->title->SetFont(FF_FONT1,FS_BOLD);
$graph->xaxis->title->SetFont(FF_FONT1,FS_BOLD);

// Display the graph
$graph->Stroke();
?>
1) include_path に、ライブラリのパスを設定する 2) include の記述を変更
拡張子:
set_include_path( "/user/php/jpgraph-1.21b/src" );

include ("jpgraph.php");
include ("jpgraph_bar.php");
メンテナンス

font パスの指定 ( No.1 )
日時: 2007/09/01 21:58
名前: lightbox


日時: 2007/09/01 21:58
名前: lightbox
  jpg-config.inc.php
拡張子:
//------------------------------------------------------------------------
// Directories for cache and font directory. 
//
// CACHE_DIR:
// The full absolute name of the directory to be used to store the
// cached image files. This directory will not be used if the USE_CACHE
// define (further down) is false. If you enable the cache please note that
// this directory MUST be readable and writable for the process running PHP.
// Must end with '/'
//
// TTF_DIR:
// Directory where TTF fonts can be found. Must end with '/'
//
// The default values used if these defines are left commented out are:
//
// UNIX:
//   CACHE_DIR /tmp/jpgraph_cache/
//   TTF_DIR   /usr/X11R6/lib/X11/fonts/truetype/
//   MBTTF_DIR /usr/share/fonts/ja/TrueType/
//
// WINDOWS:
//   CACHE_DIR $SERVER_TEMP/jpgraph_cache/
//   TTF_DIR   $SERVER_SYSTEMROOT/fonts/
//   MBTTF_DIR $SERVER_SYSTEMROOT/fonts/
//
//------------------------------------------------------------------------
// DEFINE("CACHE_DIR","/tmp/jpgraph_cache/");
// DEFINE("TTF_DIR","/usr/X11R6/lib/X11/fonts/truetype/");
// DEFINE("MBTTF_DIR","/usr/share/fonts/ja/TrueType/");
DEFINE("TTF_DIR","/user/php/font/");
DEFINE("MBTTF_DIR","/user/php/font/");
拡張子:
// Japanese TrueType font used with FF_MINCHO, FF_PMINCHO, FF_GOTHIC, FF_PGOTHIC
DEFINE('MINCHO_TTF_FONT','elenat.ttf');
DEFINE('PMINCHO_TTF_FONT','elenat.ttf');
DEFINE('GOTHIC_TTF_FONT','elenat.ttf');
DEFINE('PGOTHIC_TTF_FONT','elenat.ttf');
elenat.ttf はフリーフォント ※ 自分の環境で自由に設定する
このアーティクルの参照用URLをクリップボードにコピー メンテナンス
表示 ( No.2 )
日時: 2007/09/01 21:28
名前: lightbox
キャラクタセットは、EUC-JP で記述しています



拡張子:
<?php
set_include_path( "/user/php/jpgraph-1.21b/src" );

include ("jpgraph.php");
include ("jpgraph_bar.php");

$datay=array(12,8,19,3,10,5);

// Create the graph. These two calls are always required
$graph = new Graph(300,200,"auto");	
$graph->SetScale("textlin");

// Add a drop shadow
$graph->SetShadow();

// Adjust the margin a bit to make more room for titles
$graph->img->SetMargin(40,30,20,40);

// Create a bar pot
$bplot = new BarPlot($datay);
$graph->Add($bplot);

// Setup the titles

// 内部コード設定
mb_language( "ja" );
mb_internal_encoding("EUC-JP");

// UTF-8 に変換
$str = "シンプル棒グラフ";
$str = mb_convert_encoding ( $str, "UTF-8" );

$graph->title->Set( $str );
$graph->xaxis->title->Set( mb_convert_encoding ( "x 座標", "UTF-8" ) );
$graph->yaxis->title->Set( mb_convert_encoding ( "y 座標", "UTF-8" ) );

// フリーフォントの指定
$graph->title->SetFont(FF_GOTHIC);
$graph->yaxis->title->SetFont(FF_GOTHIC);
$graph->xaxis->title->SetFont(FF_GOTHIC);

// Display the graph
$graph->Stroke();
?>
このアーティクルの参照用URLをクリップボードにコピー メンテナンス
DB と連携 ( No.3 )
日時: 2018/02/04 18:31
名前: lightbox


ローカルでテストしているので、表示とDB のキャラクタセットが一致していないので
$conf_db_charset をセットしています。
DB から読み出されたデータは、自動的に変換されます。
( MySQL 4.1 以上の場合は $conf_db_connect_action = "set names 'ujis'"; でもかまいません )

PHP 用 リモート db クラス利用方法

拡張子:
<?

$conf_client_charset = "euc-jp";
$conf_common_path1 = "http://lightbox.in.coocan.jp/gensjis/";
$conf_common_path2 = "http://lightbox.in.coocan.jp/gen/";

$conf_db_type = 1;
$conf_db_host = "localhost";
$conf_db_db = "lightbox";
$conf_db_user = "root"; 
$conf_db_pass = ""; 
$conf_db_charset = 'SHIFT_JIS';

?>
拡張子:
<?
set_include_path( "/user/php/jpgraph-1.21b/src" );
# **********************************************************
# 外部ファイル
# **********************************************************
require_once( "conf.php" );
require_once( "{$conf_common_path1}common.txt" );
require_once( "{$conf_common_path2}db.txt" );
include ("jpgraph.php");
include ("jpgraph_bar.php");

# **********************************************************
# 接続
# **********************************************************
$SQL = new DB( "localhost", "lightbox", "root", ""  );

$Query = "select * from 社員マスタ";
$Query .= " where 社員コード <= '0010'";
$Query .= " order by 社員コード";
$Column = $SQL->QueryEx( $Query );
$first = $Column['氏名'];
$datay = array();
while( $Column ) {

	$datay[] = floor( $Column['給与'] / 10000 );
	$Column = $SQL->QueryEx( );
}

# **********************************************************
# 接続解除
# **********************************************************
$SQL->Close();

// Create the graph. These two calls are always required
$graph = new Graph(600,300,"auto");	
$graph->SetScale("textlin");

// Add a drop shadow
$graph->SetShadow();

// Adjust the margin a bit to make more room for titles
$graph->img->SetMargin(40,30,20,40);

// Create a bar pot
$bplot = new BarPlot($datay);
$graph->Add($bplot);

// Setup the titles

// 内部コード設定
mb_language( "ja" );
mb_internal_encoding("EUC-JP");

// UTF-8 に変換
$str = $first;
$str = mb_convert_encoding ( $str, "UTF-8" );

$graph->title->Set( $str );
$graph->xaxis->title->Set( mb_convert_encoding ( "x 座標", "UTF-8" ) );
$graph->yaxis->title->Set( mb_convert_encoding ( "y 座標", "UTF-8" ) );

// フリーフォントの指定
$graph->title->SetFont(FF_GOTHIC);
$graph->yaxis->title->SetFont(FF_GOTHIC);
$graph->xaxis->title->SetFont(FF_GOTHIC);

// Display the graph
$graph->Stroke();
?>
このアーティクルの参照用URLをクリップボードにコピー メンテナンス