| 제목 | [라이브러리추가] 구글 그래프 사용 | ||
|---|---|---|---|
| 글쓴이 | 준이 | 작성시각 | 2009/12/03 15:42:14 |
|
|
|||
http://www.phpclasses.org/browse/package/5802.html 여기에 있는 소스를 참고 하였구요;;![]() <설치방법> -controller폴더에 chart.php 생성 -application/libraries폴더에 GoogleChart.php 생성 http://ci설치경로/chart 로 확인하기. application/controllers/chart.php
<?php
class Chart extends Controller
{
function Chart()
{
parent::Controller();
$this->load->library('googlechart');
}
function index()
{
$values = array(
'IE7' => 22,
'IE6' => 30.7,
'IE5' => 1.7,
'Firefox' => 36.5,
'Mozilla' => 1.1,
'Safari' => 2,
'Opera' => 1.4
);
foreach ($values as $key => $val)
{
$label[] = $key;
$data[] = $val;
}
$label = implode('|', $label);
$data = implode(',', $data);
$this->googlechart->setType("p3");
$this->googlechart->setSize("500", "200");
$this->googlechart->setTitle("Browser");
$this->googlechart->setTCS("000000", "20");
$this->googlechart->setData("{$data}");
$this->googlechart->setLabel("{$label}");
$this->googlechart->setLegend("{$label}");
$this->googlechart->setColor("FF0000");
$this->googlechart->showChart();
}
}
application/libraries/GoogleChart.php
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
/*
Google Chart Class | PHP 5
jonathan.discipulo@wideout.com
Build 1.0
*/
// }}
// {{ GoogleChart
class GoogleChart {
var $size;
var $data;
var $fill;
var $multi;
var $type;
var $title;
var $tcs;
var $label;
var $legend;
var $color;
var $api;
var $url;
// }}
// {{ Constructor
function __construct() {
$this->api = "http://chart.apis.google.com/chart";
return true;
}
// }}
// {{ setType
function setType( $type ) {
/*
Chart Types
http://code.google.com/apis/chart/types.html
Line charts (lc, ls, lxy)
Bar charts (bhs, bvs, bhg, bvg)
Pie charts (p, p3, pc)
Venn diagrams (v)
Scatter plots (s)
Radar charts (r, rs)
Maps (t)
Google-o-meters (gom)
QR codes (qr)
*/
$this->type = "cht={$type}";
}
// }}
// {{ setSize
function setSize( $width, $height ) {
$this->size = "chs={$width}x{$height}";
}
// }}
// {{ setFill
function setFill( $fill ) {
$this->fill = "chf={$fill}";
}
// }}
// {{ setMultiFill
function setMultiFill( $multi ) {
$this->multi = "chm={$multi}";
}
// }}
// {{ setColor
function setColor( $color ) {
$this->color = "chco={$color}";
}
// }}
// {{ setTitle
function setTitle( $title ) {
$this->title = "chtt={$title}";
}
// }}
// {{ setTCS
function setTCS( $tc, $ts ) {
$this->tcs = "chts={$tc},{$ts}";
}
// }}
// {{ setData
function setData( $data ) {
$this->data = "chd=t:{$data}";
}
// }}
// {{ setLabel
function setLabel( $label ) {
$this->label = "chl={$label}";
}
// }}
// {{ setLegend
function setLegend( $legend ) {
$this->legend = "chdl={$legend}";
}
// }}
// {{ showURL
function showURL() {
$this->url = $this->api . "?" .
$this->type . "&" .
$this->size . "&" .
$this->color . "&" .
$this->multi . "&" .
$this->fill . "&" .
$this->legend . "&" .
$this->title . "&" .
$this->tcs . "&" .
$this->data . "&" .
$this->label;
}
// }}
// {{ showChart
function showChart() {
$this->showURL();
echo "<img src=\"{$this->url}\" alt=\"{$this->title}\" title=\"{$this->title}\" border=\"0\" />";
}
function __destruct() {
// reserved for codes to run when this object is destructed
}
}
|
|||
| 다음글 | php 4.x 에서 profiler 의 query 문제... (1) | ||
| 이전글 | asset library (4) | ||
|
변종원(웅파)
/
2009/12/03 17:40:41 /
추천
0
좋은 정보 감사합니다.
|
|
미드필드
/
2009/12/06 16:33:59 /
추천
0
좋은 공부 되었습니다.
|
|
양승현
/
2009/12/08 09:33:13 /
추천
0
좋네요..^^;
|