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

Message ListMessage List     Post MessagePost Message

  About Cross Section plot
Posted by contour on Sep-25-2012 18:50
In reference to my previous question on 19-03-2012 about selecting two 'x' points and
calculating the z values and displaying them in a separate graph, can you provide me an
example?

Hi, as you said we did the  same for Zoom In and out options and are working properly.

Could you please solve one more problem, that is can plot a graph of the cross section of two selected points on the countour. In detail when we select two points on the contour map, in turn it has to display the varitions of the third variable in a linear graph.

thanks in advance.
Srinivasa.

  Re: About Cross Section plot
Posted by Peter Kwan on Sep-26-2012 06:01
Hi contour,

As explained in the 19-03-2012 thread that you mentioned, ChartDirector does not have a built-in function to compute cross section. You would need to compute the cross section with your own code. After you have computed the cross section, you may ask ChartDirector to plot the result. See:

http://www.chartdir.com/forum/download_thread.php?site=chartdir&bn=chartdir_general&thread=1330935256#N1332873045

I have also provided an example on how I would compute the cross section. See:

http://www.chartdir.com/forum/download_thread.php?site=chartdir&bn=chartdir_general&thread=1330935256#N1332169538

So for your case, please compute the cross section with your own code, then you may ask ChartDirector to plot the cross section. You are welcome to use and adapt my code and use it in your cross section computation code.

Regards
Peter Kwan

  Re: About Cross Section plot
Posted by contour on Sep-26-2012 13:17
Hi peter,

Thank you for your response..previously we did it in .NET version. But, now the problem is conversion into PHP part, however we understand the logic. Could you please help me in this regard ie provide me the respective code in PHP version.
Peter Kwan wrote:

Hi contour,

As explained in the 19-03-2012 thread that you mentioned, ChartDirector does not have a built-in function to compute cross section. You would need to compute the cross section with your own code. After you have computed the cross section, you may ask ChartDirector to plot the result. See:

http://www.chartdir.com/forum/download_thread.php?site=chartdir&bn=chartdir_general&thread=1330935256#N1332873045

I have also provided an example on how I would compute the cross section. See:

http://www.chartdir.com/forum/download_thread.php?site=chartdir&bn=chartdir_general&thread=1330935256#N1332169538

So for your case, please compute the cross section with your own code, then you may ask ChartDirector to plot the cross section. You are welcome to use and adapt my code and use it in your cross section computation code.

Regards
Peter Kwan

  Re: About Cross Section plot
Posted by Peter Kwan on Sep-27-2012 00:50
Attachments:
Hi,

I have just translated the sample code to PHP. Note that the PHP sample code assumes "getchart.php" to be in the same directory as the script. ("getchart.php" is a standard utility that comes with ChartDirector for PHP. It is at "ChartDirector/phpdemo/getchart.php" in the ChartDirector download.)

Hope this can help.

Regards
Peter Kwan
scattercontour.php
<?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>