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

Message ListMessage List     Post MessagePost Message

  Problem contour chart
Posted by Nico on Jul-12-2013 01:57
Attachments:
Hi,

I previously posted this message on the general forum but I just noticed that it was not the right place, sorry for the duplicate topic and my bad English (I use google for translation). I put the French translation below.

I have a problem in the creating of contour charts in PHP with the library but I do not
know how to fix it. You can view my problem on the picture join to this message.

When there are large differences in values ​​between 3 points, the regularity of the
interpolation and coloration does not happen and it appears triangles and lines. This is
not
beautiful ... Is this normal?

Thank you in advance for your help.

Regards.

Nico.

#### French #####
Bonjour,
j'ai pr?c?demment post? ce message sur le forum g?n?ral mais je viens de m'aper?evoir que ce n'?tait pas au bon endroit, d?sol? pour le sujet doublons ainsi que de mon mauvais anglais (j'utilise google pour la traduction).
J'ai un probl?me dans ma cr?ation de contour charts en PHP avec la librairie
ChartDirector,
mais je ne sais pas comment le r?soudre. Vous pouvez voir mon probl?me sur l'image
jointe ? ce message.
Quand il y a de grandes diff?rences de valeurs entre 3 points, la r?gularit? de
l'interpolation et de la coloration ne se fait pas bien et des triangles et lignes deviennent
visibles. Ce n'est pas esth?tique ... Est-ce normal ?
Merci d'avance pour votre aide.
Au revoir.
Nico.
photo.PNG

  Re: Problem contour chart
Posted by Peter Kwan on Jul-12-2013 02:55
Hi Nico,

What you see is normal if you are using "smooth interpolation" (the default).

Consider the two points "27 and 21.5" near the center of the chart. They are close together, but the values are very different. So they create a steep slope. In smooth interpolation, the slope will be assumed to continue to the right and left sides. So to the right of 21.5, the interpolation may estimate it as 16. Therefore it may create a cold spot to the right of 21.5, and the temperature can suddenly change from hot to cold.

For your case, as you are not plotting the "contours", may be you can consider to use "linear interpolation", like:

$myContourLayer->setSmoothInterpolation(false);

In "interpolation", the slope will not be assumed to continue to the right or left, and so it avoid the cold spot.

Regards
Peter Kwan

  Re: Problem contour chart
Posted by Nico on Jul-12-2013 05:22
Hi Peter,

Thank you for your response.

I just tested my script and the problem of "cold spot" is solved, thank you.

However, it still appears the lines between my points and the gradient is not linear, is this normal or a solution is possible with a library function?

Here is my script:

$c = new XYChart($largeur, $hauteur);
$c->setPlotArea(0, 0, ($largeur - 1), ($hauteur - 1), -1, -1, -1, 0, 0);

$layer = $c->addContourLayer($dataX, $dataY, $dataZ);

$layer->setContourColor(Transparent);
$layer->setSmoothInterpolation(false);
//$layer->setZBounds(min($dataZ), max($dataZ));

$cAxis = $layer->setColorAxis($largeur, $hauteur, Left, 370, Right);
$cAxis->setBoundingBox(0xdcb2ff, 0x444444);

$cAxis->setLinearScale($min, $max, $precision);

$cAxis->setReverse(true);

$cAxis->setColorGradient($gradient, $array_color, -1, -1);

$c->makeChart("/tmp/trace_carte2.png");

If I want include "$layer->setZBounds(min($dataZ), max($dataZ));", I could solve my problem ? (Because my script give an error if I put this line for test ... :()

I hope not too much to ask ...

Thank you very much.

Regards.

  Re: Problem contour chart
Posted by Peter Kwan on Jul-13-2013 00:44
Hi Nico,

For the issue with setZBounds, are you sure you are using ChartDirector 5.1? In particular, is the "phpchartdir.php" you are using from ChartDirector 5.1 or 5.1.1?

Sometimes people copies "phpchartdir.php" to their own script directory. So when they upgrade the ChartDirector to 5.1, they forgot to copy the new "phpchartdir.php" to their own script directory again. In this case, the new APIs in ChartDirector 5.1 will not be found.

Regards
Peter Kwan

  Re: Problem contour chart
Posted by Nico on Jul-13-2013 02:52
Hi Peter,

I just updated to the latest version downloaded on the site but the problem is still there ...

I completely replaced the directory /var/www/ChartDirector and the files libchart.so and phpchartdir530.dll in my PHP directory /usr/lib/php5/2009.../ but nothing happens ...

My error : Fatal error :  unknown method ContourLayer.setZBounds in /var/www/lib/ChartDirector/lib/phpchartdir.php on line 2383

NB : I use the 64 bits version.

Nico.

  Re: Problem contour chart
Posted by Peter Kwan on Jul-16-2013 00:17
Hi Nico,

Have you restarted the Apache after changing the "libchartdir.so" shared object? (Note that it is "libchartdir.so", not "libchart.so".)

You mentioned you have replaced the direcotory "/var/www/ChartDirector". However, the actual error is in the directory "/var/www/lib/ChartDirector/....". Assuming you really mean you have replaced the files in the directory "/var/www/lib/ChartDirector/....", is it possible to try to run the diagnostic script ChartDirector/phpdemo/cdinfo.php and see what is the result? It should be at the URL:

http://localhost/lib/ChartDirector/phpdemo/cdinfo.php

When the above code is run, does it mention ChartDirector 5.0 or 5.1 or 5.1.1?

The error "unknown method ContourLayer.setZBounds" can occur if you are using the "phpchartdir.php" from 5.1.1, but the "libchartdir.so" is from 5.0.

If the above still does not solve the problem, is it possible to inform me what is the output of "cdinfo.php"?

Regards
Peter Kwan

  Re: Problem contour chart
Posted by Nico on Jul-16-2013 03:42
I'm really sorry, I did not libchartdir.so changed by error, it is testing the link you sent me
that I've noticed.

Now no errors with setZbounds () but I do not see any change in the quality of
interpolation on the charts. Is it is really useful to add?

Thank you for your help.

Regards.

Nico.

  Re: Problem contour chart
Posted by Peter Kwan on Jul-17-2013 04:05
Hi Nico,

I suspect may be the interpolation is accurate and the chart simply reflects your data. The sharp color changes is because your data changes abruptly.

For a contour chart, the input only has a few points. But to draw the chart, ChartDirector needs to know the value at every pixel. So some computation is needed to estimate the value of all the pixels a the few points.

The ideal estimation method depends on the nature of the data. For example, if the data are electric field strengh, electromangetic theory should be used for estimation. If the data are temperature on a plain solid surface, thermodynamic theory should be used for estimation. If the data are air temperature on the earth surface, some atmospheric science theory should be used for the estimation.

However, ChartDirector is not aware of the nature of the data, and does not know all these theories. So it just use "geometic interpolation". For scattered data, it first separate the surface into triangles, then interpolate the triangles. The interpolation method ensures the pixel values are "continuous" (there will not be a "cliff"). However, we can still see sharp changes in pixel values if your data values really changes sharply.

Also, because the "geometic interpolation" are not based on physical theories, it may not look natural for certain data type. For highly accurate contour chart using only a few data points, the following method are often used:

(a) Interpolate from the few data points into more gridded points using the correct physical theory. For example, in your case, you may use some theory more appropriate to atmospheric temperatures to interpolate your data to 20 x 20 points.

(b) Pass the 20 x 20 points to ChartDirector to plot the contour chart.

Regards
Peter Kwan

  Re: Problem contour chart
Posted by Nico on Jul-17-2013 04:26
Hi,

Ok, I understand. Since I applied the setSmoothInterpolation (false), the "transition" color
is more "fluid" and there is much less "cliff" as you say. Moreover, at times, we see many
triangles you mentioned.
How can I make the method of 20 x 20 points in the ContourChart script ? Do you have an
example or a link, or is it a script to create your own to share?

Thank you for your advice. Sorry to ask you a lot.

Regards.

Nico.

  Re: Problem contour chart
Posted by Peter Kwan on Jul-17-2013 23:30
Hi Nico,

There are hundreds of methods to generate 20 x 20 points from a few points. You would need to choose one that fit with the nature of your data (I believe your data are atmospheric air temperature). If you are not sure which method are suitable for your data type, may be you can just try some of them to see which one works. If your data only have a few points (less than 200), you may try Shepard's method, which is easy to implement. See:

http://en.wikipedia.org/wiki/Inverse_distance_weighting

Basically, the Shepard's method computes the value at a point as the weighted average of the input data points. The weight depends on distance. So points nearly will have more weights, while points far away will have less weight. There is a configurable parameter (the exponent p) that determines how quickly the weight decay with the distance.

Hope this can help.

Regards
Peter Kwan