Pear::Image_Graph その5
Image_Graph ロ-ソク足基本 PHP ファイル
p_gra-cand.php
63Pear Villageに戻る
<?php
require_once 'Image/Graph.php';
// create the graph
$Graph = Image_Graph::factory
('graph', array(300, 400));
$Font =
$Graph -> addNew
('font', 'fonts/ipaexm');
/*
日本語を含むフォントを指定
.ttf は省略可
*/
$Font->setSize(8);
$Graph->setFont($Font);
// create the plotareas
$Graph->add(
Image_Graph::vertical(
Image_Graph::factory('title', array(
'℃ 気温変化-ロ-ソク足表示 ',
12)),
Image_Graph::vertical(
$Plotarea =
Image_Graph::factory('plotarea'),
$Legend =
Image_Graph::factory('legend'),
85),
5)
);
$Legend -> setPlotarea($Plotarea);
$Plotarea -> setFillColor('white');
// create the dataset
$Dataset = Image_Graph::factory('dataset');
$Dataset -> addPoint(1,array(
'min' => 21,
'open' => 22,
'close'=> 25,
'max' => 26));
$Dataset->addPoint(2,array(
'min' => 20,
'open' => 25,
'close'=> 21,
'max' => 27));
$Dataset->addPoint(3,array(
'min' => 19,
'open' => 21,
'close'=> 24,
'max' => 25));
$Dataset->addPoint(4,array(
'min' => 21,
'open' => 24,
'close'=> 27,
'max' => 28));
$Grid = $Plotarea -> addNew
('line_grid', null, IMAGE_GRAPH_AXIS_X);
$Grid -> setLineColor('lightgray@0.1');
$Grid = $Plotarea -> addNew
('line_grid', null, IMAGE_GRAPH_AXIS_Y);
$Grid -> setLineColor('lightgray@0.1');
$Plot = $Plotarea -> addNew
('Image_Graph_Plot_CandleStick',
array($Dataset));
$Fill = Image_Graph::factory
('Image_Graph_Fill_Array');
$Fill -> addColor('green@0.4', 'red');
$Fill -> addColor('red@0.4', 'green');
$Plot -> setFillStyle($Fill);
$Plot -> setTitle(
'CandleStick Chart Daily 2017/6/1~4');
$AxisX = $Plotarea ->
getAxis(IMAGE_GRAPH_AXIS_X);
//$AxisX->setFontAngle('vertical');
$AxisX -> setLabelInterval(1);
$AxisY = $Plotarea ->
getAxis(IMAGE_GRAPH_AXIS_Y);
$AxisY -> setLabelInterval(2);
$AxisY -> forceMinimum(18);
$AxisY -> forceMaximum(30);
/*
$AxisY -> setTitle('Stock Price',
array('size' => 10, 'angle' => 90));
$AxisY -> setTitle('円',
array('size' => 12, 'angle' => 0));
*/
$Legend -> setFontSize(10);
//output the Graph
//$Graph->done();
// グラフの出力
$filename = 'img/plot_cand.png';
$Graph -> done(
array(
'filename' => $filename)
);
echo "<img src = $filename>";
?>