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

Message ListMessage List     Post MessagePost Message

  Contour chart
Posted by Nico on Jan-26-2013 05:49
Attachments:
Hello, sorry if my english is bad, I'm French (thank you Google Translate!).

I want to create a weather map for temperature. I chose the chart "Scattered Data Contour Chart" to make it with PHP.

I managed to create a card with my own ideas but I would like the ends of my area points are the edges of the graph. I tried putting 4 points in the 4 corners of the chart with value as the average temperature of all my points, but I wonder if there is not an easier method ?

My code:

----------------------------------

# Temperature average (code that I want to avoid that fills the entire area)
$avg = array_sum($dataZ)/count($dataZ);

$dataX[] = 0;
$dataY[] = 0;
$dataZ[] = $avg;

$dataX[] = 10;
$dataY[] = 0;
$dataZ[] = $avg;

$dataX[] = 0;
$dataY[] = 10;
$dataZ[] = $avg;

$dataX[] = 10;
$dataY[] = 10;
$dataZ[] = $avg;

# Create a XYChart object of size 1000 x 1000 pixels
$c = new XYChart(1000, 1000);

# Set the plotarea at (65, 40) and of size 360 x 360 pixels. Use semi-transparent
# black (c0000000) for both horizontal and vertical grid lines
$c->setPlotArea(0, 0, 999, 999, Transparent, -1, -1, -1, -1);

# Add a scatter layer to the chart to show the position of the data points
$c->addScatterLayer($dataX, $dataY, $dataZ, Cross2Shape(0.2), 7, 0x000000);

# Add a contour layer using the given data
$layer = $c->addContourLayer($dataX, $dataY, $dataZ);

# Add a color axis (the legend) in which the top center is anchored at (245, 455).
# Set the length to 330 pixels and the labels on the top side.
$cAxis = $layer->setColorAxis(0, 0, TopCenter, 0, Top);

# Set the color axis range as 0 to 20, with a step every 2 units
$cAxis->setLinearScale(-30, 40, 10);

$cAxis->setColorGradient(true);

----------------------------------

My code is correct but according to the position of the points and their values, wrong color and wrong splines appear, which distorts my card ...

Do you have an idea for me? Thank you for your help.

Nico.
form cd.png

  Re: Contour chart
Posted by Peter Kwan on Jan-28-2013 00:39
Hi Nico,

There is no standard method to estimate the values at corners if they are outside your data region. Some people will use the value of the "nearest point", or the average value or weight average value of the "nearest 3 points".

For your charts, you mentioned there are wrong color and wrong splines". However, I cannot see what is wrong. Would you mind to clarify?

For the colors, in your case, you are using "$cAxis->setLinearScale(-30, 40, 10);", and the chart seems to reflect your color scale accurately.

In a contour chart, your code provides the temperature at some points. ChartDirector would need to determine the temperature at all points in the map so as to color the map and obtain the contours. So basically, ChartDirector uses some algorithm to estimate the temperature for every pixel. This determines the pixel colors and the contour position. So it is possible the contours will be slightly different if your have different number of pixels in the chart. (It is like when drawing a weather map for France, the temperature variations within the streets in a city will be ignored, and the map may ends up with slightly different contours depending on the "level of details".)

Also, if you have more data points (eg. points at the corners), the colors and contours may change. It is because the colors and contours are based on the "estimation" of the temperature for every pixel. The "estimation" is based on your available data. If you have different data, the "estimation" may be different.

Hope this can help.

Regards
Peter Kwan

  Re: Contour chart
Posted by Nico on Jan-28-2013 04:09
Hi Peter.

Thank you for your quick response.

I'll try with the value of the nearest points of the 4 corners and see what happens.

To answer your question, I realized that problems appeared at the corners with my method. With no example for the moment, I'll post a picture where these problems occur ;).

See you soon.

Nico.

  Re: Contour chart
Posted by Nico on Jan-28-2013 04:24
Just one last question.

Can be assigned a color according to value with an array key in PHP?

An example :

$array_color = array('-30' => 0x0000ff, '0' => 0xffffff, '10' => 0x00ffff , '30' => 0xff0000, '40' => 0x000000);


Instead of :

$array_color = array(0x0000ff, 0xffffff, 0x00ffff, 0xff0000, 0x000000);
$cAxis->setColorGradient(true, $array_color, -1, -1);

Thank you for your help.

Nico.

  Re: Contour chart
Posted by Peter Kwan on Jan-28-2013 23:30
Hi Nico,

Currently, the colors must be specified for equally spaced intervals. For example, for your case, you may specify the colors at -30, -20, -10, 0, 10, 20, 30, 40 (8 colors), then use:

$cAxis->setColorGradient(true, $myColors, -1, -1);
$cAxis->setLinearScale(-30, 40, 10);

Hope this can help.

Regards
Peter Kwan

  Re: Contour chart
Posted by Nico on Feb-01-2013 05:32
Thank you for your help :).

See you.

Nico