<?php
require_once("../lib/phpchartdir.php");
# The (x, y, z) coordinates of the scattered data
$dataX = array(0.5, 1.9, 4.9, 1.0, 8.9, 9.8, 5.9, 2.9, 6.8, 9.0, 0.0, 8.9, 1.9, 4.8,
2.4, 3.4, 7.9, 7.5, 4.8, 7.5, 9.5, 0.4, 8.9, 0.9, 5.4, 9.4, 2.9, 8.9, 0.9, 8.9,
10.0, 1.0, 6.8, 3.8, 9.0, 5.3, 6.4, 4.9, 4.5, 2.0, 5.4, 0.0, 10.0, 3.9, 5.4, 5.9,
5.8, 0.3, 4.4, 8.3);
$dataY = array(3.3, 3.0, 0.7, 1.0, 9.3, 4.5, 8.4, 0.1, 0.8, 0.1, 9.3, 1.8, 4.3, 1.3,
2.3, 5.4, 6.9, 9.0, 9.8, 7.5, 1.8, 1.4, 4.5, 7.8, 3.8, 4.0, 2.9, 2.4, 3.9, 2.9,
2.3, 9.3, 2.0, 3.4, 4.8, 2.3, 3.4, 2.3, 1.5, 7.8, 4.5, 0.9, 6.3, 2.4, 6.9, 2.8,
1.3, 2.9, 6.4, 6.3);
$dataZ = array(6.6, 12.5, 7.4, 6.2, 9.6, 13.6, 19.9, 2.2, 6.9, 3.4, 8.7, 8.4, 7.8,
8.0, 9.4, 11.9, 9.6, 15.7, 12.0, 13.3, 9.6, 6.4, 9.0, 6.9, 4.6, 9.7, 10.6, 9.2,
7.0, 6.9, 9.7, 8.6, 8.0, 13.6, 13.2, 5.9, 9.0, 3.2, 8.3, 9.7, 8.2, 6.1, 8.7, 5.6,
14.9, 9.8, 9.3, 5.1, 10.8, 9.8);
$c = new XYChart(500, 500);
$c->setPlotArea(0, 0, 500, 500, Transparent, Transparent, Transparent, Transparent,
Transparent);
$c->xAxis->setColors(Transparent);
$c->yAxis->setColors(Transparent);
$layer = $c->addContourLayer($dataX, $dataY, $dataZ);
$cAxis = $layer->colorAxis();
$cAxis->setLinearScale(0, 20, 20);
$cAxis->setColorGradient(true, array(0x000000, 0xffffff));
$d = $c->makeChart3();
$startX = $c->getXCoor($dataX[0]);
$startY = $c->getYCoor($dataY[0]);
$endX = $c->getXCoor($dataX[count($dataX) - 1]);
$endY = $c->getYCoor($dataY[count($dataY) - 1]);
$distance = sqrt(($endX - $startX) * ($endX - $startX) + ($endY - $startY) * ($endY - $startY));
$z = array_pad(array(), 100, 0);
$t = array_pad(array(), 100, 0);
for ($i = 0; $i < count($z); ++$i)
{
$x = ($startX * (count($z) - 1 - $i) + $endX * $i) / (count($z) - 1);
$y = ($startY * (count($z) - 1 - $i) + $endY * $i) / (count($z) - 1);
$greyLevel = $d->getPixel($x, $y) & 0xff;
$z[$i] = ($cAxis->getMaxValue() * $greyLevel + $cAxis->getMinValue() * (255 - $greyLevel)) / 255;
$t[$i] = sqrt(($startX - $x) * ($startX - $x) + ($startY - $y) * ($startY - $y)) / $distance;
}
$d->circle($startX, $startY, 5, 5, 0x00ff00, 0x00ff00);
$d->circle($endX, $endY, 5, 5, 0xff0000, 0xff0000);
$chart1URL = $c->makeSession("chart1");
$c2 = new XYChart(600, 300);
$c2->setPlotArea(50, 30, 520, 240);
$layer2 = $c2->addLineLayer($z);
$layer2->setXData($t);
$chart2URL = $c2->makeSession("chart2");
?>
<html>
<body>
<img src="getchart.php?<?php echo $chart1URL?>">
<br/>
<img src="getchart.php?<?php echo $chart2URL?>">
</body>
</html> |