Pear::Image_Graph その5
Image_Graph ロ-ソク足 PHP ファイル
p_gra-cand-1.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[0] =
Image_Graph::factory('dataset');
$Dataset[0] ->
setName('Forecast-Max');
$Dataset[1] =
Image_Graph::factory('dataset');
$Dataset[1] ->
setName('Forecast-Min');
$Dataset[2] =
Image_Graph::factory('dataset');
$Dataset[0] -> addPoint(1,27);
$Dataset[0] -> addPoint(2,27);
$Dataset[0] -> addPoint(3,26);
$Dataset[0] -> addPoint(4,28);
$Dataset[1] -> addPoint(1,20);
$Dataset[1] -> addPoint(2,19);
$Dataset[1] -> addPoint(3,19);
$Dataset[1] -> addPoint(4,21);
$Dataset[2] -> addPoint(1,array(
'min' => 21,
'open' => 22,
'close'=> 25,
'max' => 26));
$Dataset[2] -> addPoint(2,array(
'min' => 20,
'open' => 25,
'close'=> 21,
'max' => 27));
$Dataset[2] -> addPoint(3,array(
'min' => 19,
'open' => 21,
'close'=> 24,
'max' => 25));
$Dataset[2] -> addPoint(4,array(
'min' => 21,
'open' => 24,
'close'=> 27,
'max' => 28));
$Plot[0] = $Plotarea->addNew
('area', array($Dataset[0]));
$Plot[0] -> setLineColor('red');
$Plot[1] = $Plotarea -> addNew
('area', array($Dataset[1]));
$Plot[1]->setLineColor('blue');
$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[2] = $Plotarea -> addNew(
'Image_Graph_Plot_CandleStick',
array($Dataset[2]));
$Fill =
Image_Graph::factory(
'Image_Graph_Fill_Array');
$Fill -> addColor('green@0.4', 'red');
$Fill -> addColor('red@0.4', 'green');
$Plot[2] -> setFillStyle($Fill);
$Plot[2] -> 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-1.png';
$Graph -> done(
array(
'filename' => $filename)
);
echo "<img src = $filename>";
?>