|
Getting Contours without the Gradients? |
Posted by Pete on Aug-13-2012 18:39 |
|
Hi Peter,
Firstly thank you for your help last week in my updgrade to v5.0. As you recall I am decoding GRIB data used in Weather Charts. Just an update, I found the necessary decoder I needed which outputs my Gridded data in X,Y format, so can now use this directly with Chart Director.
There is a query I have, however! The main Charts used in Weather are Temperature, Pressure, Wind, and Rainfall. Using your off the shelf examples Temperature looks fine as it is usually displayed as colour gradients and optionally overlaying the Contour lines is useful too. I am then overlaying a transparent PNG of the outline of the geographic area I am showing, and it looks great.
However, when representing Pressure, as you see on all Weather Charts, I just need the contour lines. I can't work out at the moment how I can hide the gradients so I just get the contour lines. I really need a Layer which will give me the Contour lines and all the gradient colours to be transparent, as it is usual practice to overlay pressure ontop of other charts, as we don't really ever show Pressure Maps with gradients just contours, which show where areas of Low and High pressure are.
So, is there a way to produce the contour lines I need with gradients transparent. With Rainfall I would need to do a similar thing. 'Nil' precipitation would need to be transparent, and would also need to overlay the gradient colours respresenting rainfall amounts over other charts - so Nil Rainfall ideally needs to be transparent within the gradient. In the case of rainfall we don't use Contours, so I set them to Invisible (Transparent)
Regards,
Pete. |
Re: Getting Contours without the Gradients? |
Posted by Peter Kwan on Aug-14-2012 00:28 |
|
Hi Pete,
You may use ColorAxis.setColorGradient to set the contour fill color to any color you like, including the transparent color. So if you just want to have the contour, you may use:
$myColorAxis = $myContourLayer->colorAxis();
$myColorAxis->setColorGradient(true, array(Transparent, Transparent));
The same method can be used to set the contour fill color vary from Transparent to non-Transparent, like:
$myColorAxis->setColorGradient(true, array(Transparent, 0x006699ff));
(Note: the color array can have more than 2 colors if you want to have more detail gradient control.)
Hope this can help.
Regards
Peter Kwan |
Re: Getting Contours without the Gradients? |
Posted by Pete on Aug-15-2012 20:33 |
|
Hi Peter,
Yes that all works now with the transparency settings.
One more thing. I need to tell Chartdirector that a certain colour is always linked to the same value, no matter what the other Min and Max values are in the grid. So a temperature of "25" celsius is always an exact Red colour (0xCC0000), for instance. At the moment, I am getting different colours for the same value, depending on what the total range of values is in the whole dataset.
Autoscaling works well when I am zoomed out of my map as there is a wide range of values representing the temperature on a wide scale, usually -35 to +40. But, when I zoom into a smaller area, in which the range might be 18 to 25, I don't want these High temperatures showing as Blue Cold colours, but the Min and Max values will be changing all the time depending on the Area and Scale of the chart.
I guess what I am asking is, is there a way to tell chart director <-35 to -5 will go from Dark Purple to Blue to Light Blue. -5 to +5 will be shades of Light Green to Dark Green. +5 to +40> will go from Yellow to Orange to Red.
Thanks,
Pete. |
Re: Getting Contours without the Gradients? |
Posted by Peter Kwan on Aug-16-2012 22:23 |
|
Hi Pete,
For your case, you would need to specify the colors to use at -35, -30, -25, -20, ..... 30, 35, 40 (total 16 colors). The code is like:
$myColorAxis->setColorGradient(true, $myArrayOf16Colors);
$myColorAxis->setLinearScale(-35, 40, 5);
Hope this can help.
Regards
Peter Kwan |
Re: Getting Contours without the Gradients? |
Posted by Pete on Aug-20-2012 21:36 |
|
Thanks Peter, this is now working great.
I have another question regarding the contour lines - do you know a quick method of extracting values to overlay them on the contours?
In particular I would like to identify all the Lowest and Highest values within a data set and label them accordingly - I guess using a Text Object which I am fine using. But I'm pondering how to identify the 'center' of each contour area. It's usual practice with Pressure Charts used in Weather to identify the central 'Low' or 'High' pressure with a value, and obviously there are multiple 'centres' on any one chart. |
Re: Getting Contours without the Gradients? |
Posted by Peter Kwan on Aug-21-2012 00:39 |
|
Hi Pete,
If you can identify the lowest and highest values, you can add a scatter layer using those values. The scatter symbol can be set to transparent so the symbols are not visible. You can then attach the text to the symbols. The code would be something like:
$layer = $c->addScatterLayer($arrayOfXCoors, $arrayOfYCoors, "", SquareShape, 1, Transparent, Transparent);
$layer->addExtraField($anArrayOfLabels);
$layer->setDataLabelFormat("{field0}");
$t = $layer->setDataLabelStyle("arialbd.ttf", 10, 0x000000);
$t->setAlignment(Center);
Note that ChartDirector does not compute or know where are all the lowest and highest values. You would need to use your own code to identify those points.
If you are using "gridded data points" (as opposed to randomly scattered data points) and bilinear interpolation (as opposed to smooth spline surface interpolation), then if a data point is higher than the 8 points surrounding it, it is a local maximum. The situation becomes more complex if randomly scattered data points are used (as then it is hard to determine which points are the neighbouring points) or if spline surface interpolation is used.
Regards
Peter Kwan |
|