ASE Home Page Products Download Purchase Support About ASE
ChartDirector Support
Forum HomeForum Home   SearchSearch

Message ListMessage List     Post MessagePost Message

  sample Point and ficure chart PHP
Posted by icasper on Feb-27-2012 10:47
HI,

Could you provide a simple Point & figure chart sample code in PHP.

Thanks

  Re: sample Point and ficure chart PHP
Posted by Peter Kwan on Feb-28-2012 05:06
Attachments:
Hi icasper,

There is a Point and Figure example in this forum below, but it is in .NET. I have just translate it to PHP as attached.

http://www.chartdir.com/forum/download_thread.php?bn=chartdir_support&thread=1171375913

Hope this can help.

Regards
Peter Kwan
pointfigure.php
<?php
require_once("../lib/phpchartdir.php");

#Create 100 days random finance data
$noOfDays = 100;
$rantable = new RanTable(9, 6, $noOfDays);
$rantable->setDateCol(0, chartTime(2002, 9, 4), 86400, true);
$rantable->setHLOCCols(1, 100, -2, 2);
$rantable->setCol(5, 50000000, 250000000);
$timeStamps = $rantable->getCol(0);
$highData = $rantable->getCol(1);
$lowData = $rantable->getCol(2);
$openData = $rantable->getCol(3);
$closeData = $rantable->getCol(4);
$volData = $rantable->getCol(5);

#Compute the rise and fall columns
$boxSize = 1;
$reversalAmount = 3;

$boxPos[0] = ceil($closeData[0] / $boxSize) + (($closeData[0] >= $closeData[1]) ? -1 : 1);
$boxPos[1] = ceil($closeData[1] / $boxSize);
$boxTime[0] = $boxTime[1] = $timeStamps[0];
$boxCount = 2;

for ($i = 2; $i < count($timeStamps); ++$i) {
	$pos = ceil($closeData[$i] / $boxSize);
	$reversal = $pos - $boxPos[$boxCount - 1];
	if ($boxPos[$boxCount - 1] >= $boxPos[$boxCount - 2])
		$reversal = -$reversal;
		
	if ($reversal >= $reversalAmount) {
		$boxTime[$boxCount] = $timeStamps[$i];
		$boxPos[$boxCount] = $pos;
		$boxCount = $boxCount + 1;
	} else if ($reversal < 0)
		$boxPos[$boxCount - 1] = $pos;
}

$boxTime[$boxCount] = $timeStamps[count($timeStamps) - 1];

#create the rise and fall data sets
$riseCount = 0;
$fallCount = 0;
for ($i = 1; $i < $boxCount; ++$i) {
	If ($boxPos[$i - 1] > $boxPos[$i])
		$fallCount = $fallCount + $boxPos[$i - 1] - $boxPos[$i];
	else
		$riseCount = $riseCount + $boxPos[$i] - $boxPos[$i - 1];
}

for ($i = 1; $i < $boxCount; ++$i) {
	if ($boxPos[$i - 1] > $boxPos[$i]) {
		for ($j = $boxPos[$i]; $j < $boxPos[$i - 1]; ++$j) {
			$fallSymbolsY[--$fallCount] = ($j + 0.5) * $boxSize;
			$fallSymbolsX[$fallCount] = $i - 0.5;
		}
	} else {
		for ($j = $boxPos[$i - 1] + 1; $j <= $boxPos[$i]; ++$j) {
			$riseSymbolsY[--$riseCount] = ($j + 0.5) * $boxSize;
			$riseSymbolsX[$riseCount] = $i - 0.5;
		}
	}
}

#create the chart
$c = new XYChart(500, 520);
$c->setPlotArea(50, 30, 400, 400)->setGridColor(0xcccccc, 0xcccccc);

$maxValue = ceil(max($riseSymbolsY) / $boxSize) * $boxSize;
$minValue = floor(min($fallSymbolsY) / $boxSize) * $boxSize;

$symbolSize = floor(420 / (($maxValue - $minValue) / $boxSize) * 8 / 10);

$c->addScatterLayer($fallSymbolsX, $fallSymbolsY, null, Cross2Shape(0.2), $symbolSize, 0xff0000, 0xff0000);
$c->addScatterLayer($riseSymbolsX, $riseSymbolsY, null, CircleSymbol, $symbolSize, 0xff00, 0x0000000);

$c->yAxis->setLinearScale($minValue, $maxValue, $boxSize);
$c->xAxis->setLabels2(array_slice($boxTime, 1, $boxCount));
$c->xAxis->setMultiFormat(StartOfYearFilter(), "<*font=arialbd.ttf*>{value|yyyy}", StartOfMonthFilter(), "{value|mmm}", 3);
$c->xAxis->setMultiFormat(AllPassFilter(), "-");
$c->xAxis->setLabelStyle("arial.ttf", 8, 0, 90);
$c->xAxis->setTickLength(4, 0);

$c->syncYAxis(100.0/120, -40);
$c->yAxis2->setLabelFormat("{value|2}%");

# Output the chart
header("Content-type: image/png");
print($c->makeChart2(PNG));
?>

  Re: sample Point and ficure chart PHP
Posted by icasper on Feb-28-2012 08:38
Many Many Thanks...
Peter Kwan wrote:

Hi icasper,

There is a Point and Figure example in this forum below, but it is in .NET. I have just translate it to PHP as attached.

http://www.chartdir.com/forum/download_thread.php?bn=chartdir_support&thread=1171375913

Hope this can help.

Regards
Peter Kwan